Documentation generated from Tcl CVS HEAD
oo::class -
class of all classes
package require TclOO oo::class method ?arg ...?
oo::object -> oo::class
The oo::class class is the class of all classes; every class is an instance of this class, which is consequently an instance of itself. This class is a subclass of oo::object, so every class is also an object. Additional metaclasses (i.e. classes of classes) can be defined if necessary by subclassing oo::class. Note that the oo::class object hides the new method on itself, so new classes should always be made using the create method.
The constructor of the oo::class class takes an optional argument which, if present, is sent to the oo::define command (along with the name of the newly-created class) to allow the class to be conveniently configured at creation time.
The oo::class class does not define an explicit destructor. However, when a class is destroyed, all its subclasses and instances are also destroyed, along with all objects that it has been mixed into.
The oo::class class supports the following non-exported methods:
This example defines a simple class hierarchy and creates a new instance of it. It then invokes a method of the object before destroying the hierarchy and showing that the destruction is transitive.
oo::class create fruit { method eat {} { puts "yummy!" } } oo::class create banana { superclass fruit constructor {} { my variable peeled set peeled 0 } method peel {} { my variable peeled set peeled 1 puts "skin now off" } method edible? {} { my variable peeled return $peeled } method eat {} { if {![my edible?]} { my peel } next } } set b [banana new] $b eat -> prints "skin now off" and "yummy!" fruit destroy $b eat -> error "unknown command"
oo::define(n), oo::object(n)