::Sterno::defClass
::Sterno::defClass name ?body?Define a new class and return a command bound to the class. The class command becomes the identifier for the class and is used to invoke methods in the class. The form of a class command is:
$cmd class-method ?arg0? ?arg1? ...Where
class-method
is any class method.
If name
is not empty, then a command by that name
is defined that is aliased to the actual class command. This allows
for accessing the class through a predefined name rather than the dynamic
class command name. If the class is deleted, the aliased command will
also be deleted.
The optional body
is evaluated to define the class, normally defining
instance methods and fields.
There is no requirement that all fields and methods be defined in the body.
The method
and field
class methods can be called with the class command at any time to add
new members.
This commands creates a class namespace that is a child of the
::Sterno
namespace.
The following class-field is defined for each class:
self
- Contains the class command.
selfns
- Contains the class' namespace.
method
- Defines a new instance-method.
field
- Defines a new instance-field.
new
- Creates a new object that is an instance this class.
localNew
- Creates a new object that is an instance this class in the caller's
namespace.
delete
- Deletes the class and all of its objects.
fget
- Returns the value of a class-field.
fset
- Sets the value of a class-field.
::Sterno::defLocalClass
::Sterno::defLocalClass name ?body?Define a new class in the caller's namespace and return a command bound to the class. Local classes are useful because they are deleted when the defining namespace is deleted, making it possible to easily cleanup a collection of classes and their objects. Often, the namespace is a Sterno object.
method
$cmd method name args bodyDefine a new instance method
name
that will be defined in an object instantiated from this class.
The args
and body
parameters
are identical to proc
. In fact, all method
does is arrange
for a procedure to be defined in the object's namespace when it is
instantiated.
field
$cmd field name ?value?Define the a new instance field
name
.
The field will be defined and set to the optional value
in objects instantiated from this class.
Array fields may not have values assigned to elements with the
field
method.
Array elements maybe initialized in the
construct
method.
new
$cmd new ?arg0? ?arg1? ...Create an object as an instance of this class and return a command associated with that object. All of the instance methods and fields that have been specified up to this point become members of the new object. If a method
construct
has been defined, it will be called to finish initialization of the
object. The arguments
arg0
, arg1
, etc are passed to
construct
.
localNew
$cmd localNew ?arg0? ?arg1? ...Creates a new object that is an instance this class in the caller's namespace and return a command associated with that object. Local objects are useful because they are deleted when the defining namespace is deleted, making it possible to easily cleanup a collection of objects. Often, the namespace is another Sterno object.
delete
$cmd deleteDeletes the class and all of its objects.
fget
$cmd fget nameReturns the value of the class-field
name
.
fset
$cmd fset nameSets the value of the class-field
name
to
value