James said:
Along those lines, I like to distinguish between derivation and
inheritance, using the word "derivation" for an implementation
technique in the C++ language, and "inheritance" for an OO
design concept. Not all instances of derivation are
inheritance, and it's possible to implement inheritance without
using derivation (since you can use inheritance in C).
Some people also make the distinction between specializing, extending
and implementing a base class.
- Specialization: The purest OO concept of inheritance: The derived
class is a more concrete concept than the base class, which is a more
abstract, generic concept. The classical "Animal -> Dog" inheritance is
an example of specialization: "Animal" is a more generic, more abstract
concept, while "Dog" is a more concrete, more specialized concept. This
follows the classical "is-a" relationship ("a Dog is an Animal").
- Extension: The purpose of the inheritance is to have a class with the
same features as another class, but with additional features added. The
derived class supports everything that the base class supports, plus
more. This design principle is sometimes used to avoid code repetition:
If more than one class should have the exact same common
functionalities, those common functionalities are put into a common base
class and the actual classes derived from this. Whether this is a simple
case of code reuse or more of an "is-a" relationship depends on the
situation.
- Implementation: Mostly relevant with interfaces and abstract classes,
ie. classes which contain pure virtual functions which must be
implemented in a derived class. Especially the so-called interfaces
might contain nothing else than pure virtual functions, and their sole
purpose is to function as callback objects or similar. (Some might argue
that this is just a form of specialization. However, it does have its
own separate uses and idioms, eg. the already mentioned callback mechanism.)