Inheritance

Inheritance is a very useful mechanism in software development, which is used to create the class hierarchy of an object oriented system.

Booch defines inheritance as

"A relationship among classes, wherein one class shares the structure or behavior defined in one (single inheritance) or more (multiple inheritance) other classes. Inheritance defines a 'kind of' hierarchy among classes in which a subclass inherits from one or more superclasses; a subclass typically augments or redefines the existing structure and behavior of its superclasses."

[BOO91, p. 514]

Note that Java does not support multiple inheritance by definition. Due to that fact, it will not be described here.

Inheritance offers great advantages for software development:

reusability: The methods and variables once defined in a class, can be used or extended by all subclasses of that class.

reliability: Methods that worked in the superclass will also work the same way in each inherited class.

Example: Subclasses of the class "Car"

Inheritance: A 'sports car' and a 'truck' are both subclasses of the class Car
Inheritance: A "sports car" and a "truck" are both subclasses of the class Car

Although a sports car is unlike a truck, they both have something in common and thus were defined to be subclasses of a "Car". For example, both types have "a number of wheels" and also can be "accelerated". As can be seen, only the variables and methods specific for one type had to be added in the subclass.

The common methods (defined in Car) may be used by instantiated objects of the subclasses and must not be rewritten. By defining further subclasses, a class hierarchy arises, where classes in the lower part are more and more specialized. On the other hand, classes in the upper part are more generalized.

This leads us to another aspect of object orientation, which is called abstraction.

Neural Net Components in an Object Oriented Class Structure