5.1 Inheritance
Inheritance expresses sharing among classes. Classes may share a
common implementation (code and/or data), a common interface, or they
may share both implementation and interface. When inheritance is
used to create interface sharing, each class sharing the common
interface must implement the methods described in the shared
interface. Such classes may have other methods in addition to those in
the shared interface. The classes sharing a common interface can, and
usually do, implement differently the methods in the shared interface.
When inheritance is used to create implementation sharing, each of the
sharing classes builds on the shared implementation to defines its own
operations.
Inheritance extends the class concept to distinguish between a "base"
class that defines the shared interface and implementation and a
"derived" class that "inherits" the shared elements from the base
class. Equivalent terminology used in other object-oriented languages
is "superclass" and "subclass" to refer to base and derived classes,
respectively.
The Counter and Cycler classes will be used to illustrate
implementation sharing. The Clock class will then be added to show how
interface sharing is achieved.