::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.
Class fields may be defined using the Tcl variable
command in body.
The ::Sterno::defClass
command 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.
classField
- Defines a new class-field.
classMethod
- Defines a new class-method.
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.
fref
- Get the fully qualified reference (name) of a class-field.
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.
::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.
classField
$cmd classField name ?value?
Define the a new class field name.
The field will be defined and set to the optional value
in the class and will be imported into all instants of this class.
Array fields may not have values assigned to elements with the
classField method.
Array elements maybe initialized in the body of the class following the
classField command.
classMethod
$cmd classMethod name args body
Define a new class method name.
This method maybe called through the class object or an
instance object of 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 class namespace.
delete
$cmd delete
Deletes the class and all of its objects.
fget
$cmd fget name
Returns the value of the class-field name.
fset
$cmd fset name value
Sets the value of the class-field name to
value.
fref
$cmd fref field
Get the fully qualified reference (name) of class-field
field . This allows class-fields to be passed by name to
procedures and commands. For example:
array names [$obj fref table]
method
$cmd method name args body
Define 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.
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.