Main Page | See live article | Alphabetical index

Inheritance (computer science)

In computer science, inheritance creates an is a relationship between data structures.

Thus the logic proposition "Socrates is a man" states that the Socrates also has the attributes of other men. Currently Java and C++, among others, allow this type of proposition to be stated directly in the respective languages by using the Java construct subclass name extends class name, or the C++ notation subclass : class name.

Inheritance is fundamentally different than composition, where the relationship is has a instead of is a, for example, "a car has a motor".

Inheritance can also be used in interfaces to give the appearance of being whatever - for example if we have an such an interface below, these could all have a "makeNoise();" method.

Thus passing any to an Recorder.captureSoundOf(NoiseMaker()); would capture the sound emitted. Thus from the perspective of a recorder, each is a NoiseMaker.

However, there has been no small amount of inconsistency in the usage of the "is-a" link: R. J. Brachman wrote a paper titled "What IS-A is and isn't", wherein 29 different semantics were found in projects whose knowledge representation schemes involved an "is-a" link. Other links include the "has-part" or "has a" link.

In the UML, is a is a relationship symbolized with an arrow; a white arrowhead points to the superclass. The tail of the arrow rests on the subclass.

Sowa's conceptual graph places the is a in a bubble (circle). The classes [Socrates] and [Man] are placed in rectangles.

Some computer scientists, such as the principal designer of CLU, Barbara Liskov, urge that the use of inheritance be restricted to those designs which truly reflect the problem being solved, and that re-use and subtype polymorphism are not actually the strong points of a design resting solely on inheritance.

The most widely encountered practical application of inheritance is in word processors, where people often don't realize except intuitively that the components of the document are inheriting layout and style properties from their parent elements, not even when they are using style sheets for formatting. A similar impression can be seen with drawing programs.

Usage in different fields

References: