This is an implementation of prototype objects.
It replaces a previous implementation by Hans-Martin Mosner, which I extended (in an ugly way) to handle delegation of behaviour. Hans-Martin's code is still available.
Filing in this changeset and running Prototype>>newPrototype will return a prototype object, that is an object without a class.
This object will understand the following basic messages:
- parent/parent: set and retrieve the parent of the object
- addSlot:/removeSlot: add and remove a data slot
- addMethod:/removeMethod: add and remove a method
- clone return a new prototype, same as the old prototype
The code works by creating an object which is its own class. You can test this on a prototype:
|p| p := Prototype newPrototype. p == p class
should evaluate to true.
A simple clone of a prototype creates a lightweight prototype (essentially an instance) to save memory space. Changing anything (ie adding a slot etc) will result in the conversion to a heavyweight prototype.
At the moment, I think an image full of prototypes would be larger and slower; but I think that this penalty can be reduced (perhaps to nil).
Prototype objects can be inspected and altered in the inspector, debugging should work.
Download the changeset here: System-Prototypes.7
Older code
Hans-Martin Mosner wrote a changeset to allow the use of prototype object (classless objects) in Squeak. I have taken that code and added the ability to have classless objects have delegated behaviour.
Download the changeset here: Prototypes.1