Advanced PowerBuilder

HomePrevious Lesson: SuperClass
Next Lesson: Base Classes

Inheritance

Inheritance is a mechanism, which allows objects to share attributes, and services based on a predefined relationship; it allows you to define a hierarchy of objects. The inherited object is called a descendant object, while the object from which the descendant is inherited is called an ancestor.

If we define a vehicle on certain attributes such as height, weight, speed, maximum load and so on. Even though vehicles share these common attributes, they are not same. We might have a car, a truck and an emergency vehicle, each with their own specific attributes.

The first thing we need to do is define a class, called Vehicle, which has the general attributes of our vehicles. From there on, we can derive other classes such as a Car class and a Truck class by inheriting from this Vehicle class. The Vehicle class is called the ancestor, and the Car and Truck classes are called descendants.

Inheritance hierarchies are a means of classifying objects. They are inverted trees of common subroutines. We use the term inverted, to convey the sense that, the commonalty of objects is portrayed upwardly as in a tree as compared to the downward representation of common modules in a structure chart. Each higher object represents a set of services and attributes common to all levels to which it is connected below.

Each object in the tree is called the class of the objects below it. An object will inherit services and attributes as common characteristics from the class to which it belongs. This means that you need not redesign these characteristics every time you use them in an object, yet can reference them as if they were a part of the object.
HomePrevious Lesson: SuperClass
Next Lesson: Base Classes