Poet2.2 Manual Prototype Object Extension for Tcl

Object Creation and Destruction

Poet objects are created by their parent and destroy themselves:

Object construct a

(...sometime later...)

a destruct

If the name of the new object ends in *, the name is used as a prefix and an anonymous name is generated that is guaranteed to be unique within this execution of the program.  The name of the new object is returned.

% Object construct *
*7
%

If the name ends in @, the anonymous name returned is suitable for naming a persistent object--the name is guaranteed to be unique within the persistent storage.  Note that the object isn't actually persistent until Thing is mixed in, see Persistence.

Most Poet objects are autoloaded when they are first referenced (a few are loaded in advance). Since an object is created by invoking a method on its parent, the parent is guaranteed to be autoloaded first, as are its parents, and so on.

Poet does not currently implement garbage collection, but there are two means by which an object can clean up after itself when it destroys itself.
  1. The object may override the destruct method. Make sure to invoke Object destruct in your destructor using as (see Methods).
  2. An object may have attached to it any number of goodbye scripts by using the Object addGoodbye script command.  When the object destructs, each of the goodbye scripts will be invoked.
Typically, overriding the destructor is used to destroy any sub-objects created in an object's constructor.  Goodbye scripts are used when object a needs to know when object b is destroyed:

b addGoodbye {a notificationOfDestruction b}

The method notificationOfDestruction will be invoked on a when b destruct is executed.