250: Highlights
- Class hierarchies reflect subclasssuperclass relations
among classes.
- You have several reasons to arrange classes in hierarchies:
- To parallel natural categories
- To prevent avoidable duplication and to simplify maintenance
- To avoid introducing bugs into previously debugged code
- To use purchased code
An object inherits member variables and member functions not only from the
class to which it belongs, but also from all that class's superclasses.
When a subclasssuperclass chain contains multiple functions
with the same name, the one closest to the object argument in
the subclasssuperclass chain is the one executed. All others
are shadowed.
When a subclasssuperclass relation is direct, with no
intervening classes, the subclass is called the derived class and
the superclass is called the base class. The derived class is said
to be derived from the base class.
There are several types of derivations; so far, you know about
only public derivations.
If you want to create a class hierarchy,
then draw a diagram that reflects natural categories,
and populate the classes in that class
hierarchy with member variables and member functions such that there is no
needless duplication of a member variable or member function, and such that
each member variable and member function is useful in every subclass.
If you want to create a public derived-classbase-class relation, then
augment the derived-class definition by instantiating the following pattern:
class derived-class name : public base-class name { ... }