Last updated at 9:14 am UTC on 26 September 2019
Every graphical object (including strings) you see on the screen within a Morphic Project is a Morph. Morphs may be "light" or "heavy".
To save space Morph objects havew only a few instance variables. They are
For simple morphs this is sufficient. Note that the value of the 'extension' variable is not set. That is the value is 'nil'. For complex morphs it will contain a reference to a MorphExtension object. This will contains the extra information and functionality.
This shows that in Squeak and Pharo for more complex morphs an MorphExtension object (= an instance of the MorphExtension class) is attached to the Morph object in question. It keeps the additional instance variables the Morph needs. This is done with lazy initialisation.
To even add more flexibility the MorphExtension instance includes an instance variable called 'otherProperties'.
It holds an IdentityDictionary where additional data may be kept.
You may use 'otherProperties' to add your own data to a morph.
You do not have to deal with MorphExtension directly. You just use messages of the type
you simply send to the aMorph.
Note: properties have to be in the form of aSymbol, not aString.)
- AtomMorphs (Subclass of EllipseMorph with additional instance variable velocity is still a simple morph. The MorphExtension object is not used-
- TODO: add an example of a complex morph, i.e. a Morph where a MorphExtension object is attached to the Morph object.
This mechanism allows a Morph object "to grow" in complexity while still maintaining a good performance for simple, frequently used morphs.