S R T B H P N

Class Hierarchy Structures

Distinguish between Interface, Abstract class, and Concrete class

Inheritance has two main functions: 1) to support substitution of any one of a set of derived class instances, depending on the application context, and 2) to provide in one place code and resources that are shared across all derived instances.

Any base class guarantees that code which uses a pointer or reference to the base will compile and operate with a pointer or reference to any class that publically derives from the base. It is important that you design the hierarchy so clients don't need to know the implementation details that distinguish each subtype. This substitutability is the most powerful aspect of inheritance.

A base class that provides non-virtual member functions intends to provide exactly that code to each derived instance without need to define the common operations in more than one place, e.g., just in the base. Similarly, if it declares an instance of some type, it intends to provide copies to each derived instance, or, if the type is qualified as static, it intends to share that specific instance among all derived objects.

You find three kinds of class structures within inheritance hierarchies:

image file not found
Interface, Abstract Class, and Concrete Derived Classes

Conclusions:

C++ classes in an inheritance hierarchy are either interfaces, abstract base classes, or concrete derived classes.
  1. Interface classes provide a contract for service without binding the client to an implementation.
  2. Abstract base classes support sharing of code and data resources across all concrete derived classes.
  3. Publically derived concrete classes are specializations of their base type(s), providing a service unique to that class. All of these specializations should implement the metaphor defined by their base.
  4. Think of public inheritance as an "is-a" relationship between derived and base classes.