Inheritance

Inheritance is used for two purposes.
  1. We often find that objects share common behaviour. This is analogous to the way that taxonomies are built up. Thus a car and a motor bicycle have much in common, and they each have something in common with an aeroplane, but less than with each other. We quickly build up trees of relations for this sort of thing, by placing those factors which are shared in a common parent node and those which are distinct in descendent nodes. This way of classifying things gave rise to the term inheritance. An object oriented program can use this form of structuring to avoid duplicating attributes of objects when defining the classes which implement them. A common super-class can be defined containing those operations which are in common and derived sub-classes are defined which inherit this common behaviour and add to or modify it as appropriate to the more specialised definition required.
  2. A second use of inheritance, which is sometimes confusingly assumed to be the same, is to allow general purpose operations, such as those for lists, to be applied to all objects which belong to sub-classes of that for which the operation is defined in the list class. Thus the sub-classes inherit not the operations of their parents, but their parents' ability to be used in operations by some other class of object. This is sometimes said to allow such operations to be polymorphic, since they can be used on a wide variety of different types of object, which merely share the ability to be used.


Some examples of inheritance

class List_Item {
Public:
   List_Item * next;
   List_Item();
};

class Int_Item : List_Item {
public:
   int val;
};

class Float_Item : List_Item {
public:
   float val;
};


Here items with different types of value can be handled by the same list package.

Inheritance is shown by writing the parent class after the colon following the sub-class name.

Next note in series

Back to index