Overview of NewtonScript Inheritance

The Mechanics of Inheritance

Becoming acquainted with the original design requirements of the language goes a long way toward explaining the structure of inheritance and why NewtonScript provides a new form of it. The Newton has a limited amount of memory, but a fair amount of ROM (in the form of system ROM and ROM cards). The language in general and inheritance in particular was molded with this crucial point in mind.

The NewtonScript inheritance model deals with objects. These objects may inherit from other objects. Here is the important factor in the relationship:

Difference inheritance is quite unlike the classic model that you would find in standard languages such as C++. Before we compare these two models in greater detail, however, let us look at an example of NewtonScript inheritance using two objects: original and copyCat. FIGURE 4.1 shows the two objects (which are frames); copyCat is inheriting from original.

FIGURE 4.1 : One object inheriting from another.


The first object, original, contains seven slots of its own. The second object, copyCat, contains four slots:

Thus, copyCat, which contains only four direct slots, has access to a total of ten slots (six via inheritance). One of original's slots, text, is not accessible, as it is overridden.

From this example, you can see that an object can inherit from another object while maintaining unique slots of its own. As in copyCat, these unique slots can contain any of the following:

New Method
A new slot containing a method. The inheriting object (copyCat) can respond to unique messages that the other object (original) knows nothing about.

New Data
A new slot containing some data value.

Overridden Method
A method with the same name as an existing method. The existing method is masked by the overridden version (copyCat).

Overridden Data
A slot (containing data) with the same name as an existing slot. The inheriting object (copyCat) has no access to the existing slot.

Actually, there is no distinction in NewtonScript between overriding a method and overriding data. We mentioned these separately to draw your attention to both possibilities. Because many languages don't allow data to be overridden, this may have been unfamiliar to you.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996