
Overview of NewtonScript Inheritance
Comparing Prototype Inheritance and Class-Based Inheritance
As we said before, NewtonScript inheritance differs from the class-based inheritance found in languages such as C++, Smalltalk, and Object Pascal. In class-based inheritance, one class inherits from another class, and objects are created as instances of a class.
Difference (or prototype) inheritance has some advantages over class-based inheritance:
- Each object is smaller. In class-based inheritance, each object contains the union of its own data and all the data belonging to its superclasses. This makes for large objects. In difference inheritance, an object only contains a pointer to the object it is inheriting from and its own unique data. This makes for small objects.
- An object can override both methods and data.
- The inheritance is dynamic; you can change what an object inherits from by changing the inheritance pointer.
- An object has access to changes made in the object it inherits from and reflects those changes immediately, even at runtime.
The major disadvantage is speed. Accessing a slot requires searching an object and then searching its entire inheritance chain. In class-based inheritance, accessing a slot can be done in one operation. Remembering the design requirements of the Newton, the size versus speed trade-off was preordained.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996