OOP Hierarchy

Question: What would be examples of object-oriented inheritance hierarch.

Answer: A real world example of object oriented inheritance:
If we start with VEHICLE as a base class meaning anything that can transport people or things. We can now define ROAD_VEHICLE that inherits from VEHICLE (because all road vehicles are vehicles) which adds the functionality common to all road vehicles. If we next define CAR it can inherit from ROAD_VEHICLE and add of of the things that cars have in common. We could also have WATER_VEHICLE, AIR_VEHICLE and SPACE_VEHICLE that also inherit from VEHICLE and TRUCK, BUS and MOTORBIKE that inherit from ROAD_VEHICLE. You could also have TAXI inherit from CAR.

In an object oriented language types of things are defined as classes and classes can inherit from more general classes so that those aspects of the things that slightly different types of things have in common can be identified as being common and you can have processing that is dependent only on what they have in common and not on the specifica of the individual types that can act on any object that is of a class below that common class in the hierarchy. For example all road vehicles have wheels and so something involving wheels can be applied to any road vehicle whether it is a car or bus or whatever.

The individual instances of each type of object are "constructed" from the appropriate class that they belong to. The more generic classes that have other classed inherit from them may not have specific objects constructed from them but they will still be used as a part of the specification for the objects constructed from those classes that inherit from them.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow