=>Encapsulation:
When the aforementioned bike engineer creates a new bicycle, she connects together
component pieces such as the frame, handlebars, wheels, and a headlight. Each
component has certain properties and can accomplish certain behaviors. She can use
the headlight without understanding the details of how it works, as long as she
knows what it does.
To achieve this, the headlight must be self-contained. It must do one well-defined
thing and it must do it completely. Accomplishing one thing completely is called
encapsulation.
All the properties of the headlight are encapsulated in the headlight object. They are
not spread out through the bicycle.
C++ supports the properties of encapsulation through the creation of user-defined
types called classes. A well-defined class acts as a fully encapsulated entity that is
used as an entire unit or not at all. The inner workings of the class should be hidden
on the principle that the programs that use a well-defined class do not need to know
how the class works. They only need to know how to use it.
=>Inheritance and Reuse:
C++ supports the idea of reuse through inheritance. A new type can be declared that
is an extension of an existing type. This new subclass is said to derive from the existing type.Penny's bicycle is derived from a plain old bicycle and thus inherits all its
qualities but adds additional features as needed.
=>Polymorphism:
C++ supports this idea that different objects do the right thing through a language
feature called function polymorphism and class polymorphism. Polymorphism refers to
the same thing taking many forms.
No comments:
Post a Comment