1object(n) TclOO Commands object(n)
2
3
4
5______________________________________________________________________________
6
8 oo::object - root class of the class hierarchy
9
11 package require TclOO
12
13 oo::object method ?arg ...?
14
16 oo::object
17______________________________________________________________________________
18
20 The oo::object class is the root class of the object hierarchy; every
21 object is an instance of this class. Since classes are themselves
22 objects, they are instances of this class too. Objects are always
23 referred to by their name, and may be renamed while maintaining their
24 identity.
25
26 Instances of objects may be made with either the create or new methods
27 of the oo::object object itself, or by invoking those methods on any of
28 the subclass objects; see oo::class for more details. The configuration
29 of individual objects (i.e., instance-specific methods, mixed-in
30 classes, etc.) may be controlled with the oo::objdefine command.
31
32 Each object has a unique namespace associated with it, the instance
33 namespace. This namespace holds all the instance variables of the
34 object, and will be the current namespace whenever a method of the
35 object is invoked (including a method of the class of the object). When
36 the object is destroyed, its instance namespace is deleted. The
37 instance namespace contains the object's my command, which may be used
38 to invoke non-exported methods of the object or to create a reference
39 to the object for the purpose of invocation which persists across
40 renamings of the object.
41
42 CONSTRUCTOR
43 The oo::object class does not define an explicit constructor.
44
45 DESTRUCTOR
46 The oo::object class does not define an explicit destructor.
47
48 EXPORTED METHODS
49 The oo::object class supports the following exported methods:
50
51 obj destroy
52 This method destroys the object, obj, that it is invoked upon,
53 invoking any destructors on the object's class in the process.
54 It is equivalent to using rename to delete the object command.
55 The result of this method is always the empty string.
56
57 NON-EXPORTED METHODS
58 The oo::object class supports the following non-exported methods:
59
60 obj eval ?arg ...?
61 This method concatenates the arguments, arg, as if with concat,
62 and then evaluates the resulting script in the namespace that is
63 uniquely associated with obj, returning the result of the evalu‐
64 ation.
65
66 obj unknown ?methodName? ?arg ...?
67 This method is called when an attempt to invoke the method
68 methodName on object obj fails. The arguments that the user sup‐
69 plied to the method are given as arg arguments. If methodName │
70 is absent, the object was invoked with no method name at all (or │
71 any other arguments). The default implementation (i.e., the one
72 defined by the oo::object class) generates a suitable error,
73 detailing what methods the object supports given whether the
74 object was invoked by its public name or through the my command.
75
76 obj variable ?varName ...?
77 This method arranges for each variable called varName to be
78 linked from the object obj's unique namespace into the caller's
79 context. Thus, if it is invoked from inside a procedure then the
80 namespace variable in the object is linked to the local variable
81 in the procedure. Each varName argument must not have any names‐
82 pace separators in it. The result is the empty string.
83
84 obj varname varName
85 This method returns the globally qualified name of the variable
86 varName in the unique namespace for the object obj.
87
88 obj <cloned> sourceObjectName
89 This method is used by the oo::object command to copy the state │
90 of one object to another. It is responsible for copying the pro‐ │
91 cedures and variables of the namespace of the source object │
92 (sourceObjectName) to the current object. It does not copy any │
93 other types of commands or any traces on the variables; that can │
94 be added if desired by overriding this method in a subclass.
95
97 This example demonstrates basic use of an object.
98
99 set obj [oo::object new]
100 $obj foo → error "unknown method foo"
101 oo::objdefine $obj method foo {} {
102 my variable count
103 puts "bar[incr count]"
104 }
105 $obj foo → prints "bar1"
106 $obj foo → prints "bar2"
107 $obj variable count → error "unknown method variable"
108 $obj destroy
109 $obj foo → error "unknown command obj"
110
112 my(n), oo::class(n)
113
115 base class, class, object, root class
116
117
118
119TclOO 0.1 object(n)