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
You have attempted of activities on this page