Encapsulation:
Separating the implementation details of an object from how the object is used. This allows for modular design of complex programs.
They combine data and operations. This process of packaging some data along with the set of operations that can be performed on the data is called encapsulation.
Encapsulation is one of the major attractions of using objects. It provides a convenient way
to compose complex solutions that corresponds to our intuitive view of how the world works. We
naturally think of the world around us as consisting of interacting objects. Each object has its own
identity, and knowing what kind of object it is allows us to understand its nature and capabilities. I
look out my window and I see houses, cars, and trees, not a swarming mass of countless molecules
or atoms.
From a design standpoint, encapsulation also provides a critical service of separating the concerns
of “what” vs. “how.” The actual implementation of an object is independent of its use. The
implementation can change, but as long as the interface is preserved, other components that rely
on the object will not break. Encapsulation allows us to isolate major design decisions, especially
ones that are subject to change.
Another advantage of encapsulation is that it supports code reuse. It allows us to package up
general components that can be used from one program to the next.
Encapsulation is probably the chief benefit of using objects, but alone it only makes a system
object-based. To be truly objected-oriented, the approach must also have the characteristics of polymorphism and inheritance.
Polymorphism:
Different classes may implement methods with the same signature. This makes programs more flexible, allowing a single line of code to call different methods in different situations.
Literally, the word polymorphism means “many forms.” When used in object-oriented literature,
this refers to the fact that what an object does in response to a message (a method call) depends
on the type or class of the object.
Polymorphism gives object-oriented systems the flexibility for each object to perform an action
just the way that it should be performed for that object. Before object orientation, this kind of
flexibility was much harder to achieve.
Inheritance:
A new class can be derived from an existing class. This supports sharing of methods among classes and code reuse.
The third important property for object-oriented approaches, inheritance, is one that we have not
yet used. The idea behind inheritance is that a new class can be defined to borrow behavior from
another class. The new class (the one doing the borrowing) is called a subclass, and the existing
class (the one being borrowed from) is its superclass.
The material is an excerpt from John Zelle Python Programming.