6.27.7 Comparison of object models

Many object-oriented Forth extensions have been proposed (A survey of object-oriented Forths (SIGPLAN Notices, April 1996) by Bradford J. Rodriguez and W. F. S. Poehlman lists 17).

A number of Forth object-oriented models were inspired by Neon (see Object-oriented programming in ANS Forth (Forth Dimensions, March 1997) by Andrew McKewan) but this model has a number of limitations 34:

Another difference between object models is whether they have an active object such as this in objects.fs. mini-oof.fs does not have an active object, and uses the top-of-stack as the object for instance variables and the selector.

And if they have an active object, there are differences in what sets or changes it, and what make use of the active object.

In Does late binding have to be slow? (Forth Dimensions 18(1) 1996, pages 31-35) Andras Zsoter describes a model that makes heavy use of an active object (like this in objects.fs): The active object is not only used for accessing all fields, but also specifies the receiving object of every selector invocation (like in mini-oof2.fs; you have to change the active object explicitly with { ... } (similar to how you use >o ... o> in oof.fs and mini-oof2.fs). A Standard Forth implementation of this model is available through http://www.forth.org/oopf.html.

The oof.fs model combines information hiding and overloading resolution (by keeping names in various word lists) with object-oriented programming. It sets the active object implicitly on method entry, but also allows explicit changing (with >o...o> or with with...endwith). It uses parsing and state-smart objects and classes for resolving overloading and for early binding: the object or class parses the selector and determines the method from this. If the selector is not parsed by an object or class, it performs a call to the selector for the active object (late binding), like Zsoter’s model. Fields are always accessed through the active object. The big disadvantage of this model is the parsing and the state-smartness, which reduces extensibility and increases the opportunities for subtle bugs; essentially, you are only safe if you never tick or postpone an object or class (Bernd disagrees, but I (Anton) am not convinced).


Footnotes

(34)

A longer version of this critique can be found in On Standardizing Object-Oriented Forth Extensions (Forth Dimensions, May 1997) by Anton Ertl.