Objects as Extensions of Records

This idea that data areas are known simply by an offset is a key insight into how to make inheritance work. Data areas that an object inherits from its parent will be stored in exactly the same locations as they are found in the parent. New data areas will come after this, extending the data of the parent.

In this picture we have two classes from the billiard ball case study. The parent class defines the two data fields link and region. Subclasses Wall and Ball both extend these by defining new data areas, however in both cases the data fields come after the link and region areas. Thus, functions defined in the parent class, that are permitted access only to the link and region data fields, will work regardless of what type of object they are manipulating.

[audio] [real] Text to accompany slide4, in Chapter 21 of An Introduction to Object-Oriented Programming