object(3tcl) | TclOO Commands | object(3tcl) |
oo::object - root class of the class hierarchy
package require TclOO oo::object method ?arg ...?
oo::object
The oo::object class is the root class of the object hierarchy; every object is an instance of this class. Since classes are themselves objects, they are instances of this class too. Objects are always referred to by their name, and may be renamed while maintaining their identity.
Instances of objects may be made with either the create or new methods of the oo::object object itself, or by invoking those methods on any of the subclass objects; see oo::class for more details. The configuration of individual objects (i.e., instance-specific methods, mixed-in classes, etc.) may be controlled with the oo::objdefine command.
Each object has a unique namespace associated with it, the instance namespace. This namespace holds all the instance variables of the object, and will be the current namespace whenever a method of the object is invoked (including a method of the class of the object). When the object is destroyed, its instance namespace is deleted. The instance namespace contains the object's my command, which may be used to invoke non-exported methods of the object or to create a reference to the object for the purpose of invocation which persists across renamings of the object.
The oo::object class does not define an explicit constructor.
The oo::object class does not define an explicit destructor.
The oo::object class supports the following exported methods:
The oo::object class supports the following non-exported methods:
This example demonstrates basic use of an object.
set obj [oo::object new] $obj foo → error "unknown method foo" oo::objdefine $obj method foo {} {
my variable count
puts "bar[incr count]" } $obj foo → prints "bar1" $obj foo → prints "bar2" $obj variable count → error "unknown method variable" $obj destroy $obj foo → error "unknown command obj"
base class, class, object, root class
0.1 | TclOO |