20.1. Pillars of OOP¶
Object-oriented programming involves four key ideas: encapsulation, information hiding, inheritance, and polymorphism. Encapsulation is the idea that a class can package some data together with the methods that manipulate the data. This is a powerful capability, and the chief idea that distinguishes OOP from structured programming. Information Hiding promotes quality code by allowing objects to protect their state against direct manipulation by code using the object. Python, like many languages, provides mechanisms to achieve information hiding, but we do not cover them in this book. Inheritance and polymorphism are mechanisms that help to enable code reuse and contract-based programming, and are the subject of this chapter.
-
Q-1: Drag each item to its location in a class diagram
Read the chapter on functions and try again.
- encapsulation
- Packaging data and methods together
- information hiding
- protecting state (data) in objects
- inheritance
- allows code reuse
- polymorphism
- contract-based programming
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.