OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / doc / object.n
1 '\"
2 '\" Copyright (c) 2007-2008 Donal K. Fellows
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH object n 0.1 TclOO "TclOO Commands"
8 .so man.macros
9 .BS
10 '\" Note:  do not modify the .SH NAME line immediately below!
11 .SH NAME
12 oo::object \- root class of the class hierarchy
13 .SH SYNOPSIS
14 .nf
15 package require TclOO
16
17 \fBoo::object\fI method \fR?\fIarg ...\fR?
18 .fi
19 .SH "CLASS HIERARCHY"
20 .nf
21 \fBoo::object\fR
22 .fi
23 .BE
24 .SH DESCRIPTION
25 .PP
26 The \fBoo::object\fR class is the root class of the object hierarchy; every
27 object is an instance of this class. Since classes are themselves objects,
28 they are instances of this class too. Objects are always referred to by their
29 name, and may be \fBrename\fRd while maintaining their identity.
30 .PP
31 Instances of objects may be made with either the \fBcreate\fR or \fBnew\fR
32 methods of the \fBoo::object\fR object itself, or by invoking those methods on
33 any of the subclass objects; see \fBoo::class\fR for more details. The
34 configuration of individual objects (i.e., instance-specific methods, mixed-in
35 classes, etc.) may be controlled with the \fBoo::objdefine\fR command.
36 .PP
37 Each object has a unique namespace associated with it, the instance namespace.
38 This namespace holds all the instance variables of the object, and will be the
39 current namespace whenever a method of the object is invoked (including a
40 method of the class of the object). When the object is destroyed, its instance
41 namespace is deleted. The instance namespace contains the object's \fBmy\fR
42 command, which may be used to invoke non-exported methods of the object or to
43 create a reference to the object for the purpose of invocation which persists
44 across renamings of the object.
45 .SS CONSTRUCTOR
46 The \fBoo::object\fR class does not define an explicit constructor.
47 .SS DESTRUCTOR
48 The \fBoo::object\fR class does not define an explicit destructor.
49 .SS "EXPORTED METHODS"
50 The \fBoo::object\fR class supports the following exported methods:
51 .TP
52 \fIobj \fBdestroy\fR
53 .
54 This method destroys the object, \fIobj\fR, that it is invoked upon, invoking
55 any destructors on the object's class in the process. It is equivalent to
56 using \fBrename\fR to delete the object command. The result of this method is
57 always the empty string.
58 .SS "NON-EXPORTED METHODS"
59 .PP
60 The \fBoo::object\fR class supports the following non-exported methods:
61 .TP
62 \fIobj \fBeval\fR ?\fIarg ...\fR?
63 .
64 This method concatenates the arguments, \fIarg\fR, as if with \fBconcat\fR,
65 and then evaluates the resulting script in the namespace that is uniquely
66 associated with \fIobj\fR, returning the result of the evaluation.
67 .TP
68 \fIobj \fBunknown ?\fImethodName\fR? ?\fIarg ...\fR?
69 .
70 This method is called when an attempt to invoke the method \fImethodName\fR on
71 object \fIobj\fR fails. The arguments that the user supplied to the method are
72 given as \fIarg\fR arguments.
73 .VS
74 If \fImethodName\fR is absent, the object was invoked with no method name at
75 all (or any other arguments).
76 .VE
77 The default implementation (i.e., the one defined by the \fBoo::object\fR
78 class) generates a suitable error, detailing what methods the object supports
79 given whether the object was invoked by its public name or through the
80 \fBmy\fR command.
81 .TP
82 \fIobj \fBvariable \fR?\fIvarName ...\fR?
83 .
84 This method arranges for each variable called \fIvarName\fR to be linked from
85 the object \fIobj\fR's unique namespace into the caller's context. Thus, if it
86 is invoked from inside a procedure then the namespace variable in the object
87 is linked to the local variable in the procedure. Each \fIvarName\fR argument
88 must not have any namespace separators in it. The result is the empty string.
89 .TP
90 \fIobj \fBvarname \fIvarName\fR
91 .
92 This method returns the globally qualified name of the variable \fIvarName\fR
93 in the unique namespace for the object \fIobj\fR.
94 .TP
95 \fIobj \fB<cloned> \fIsourceObjectName\fR
96 .VS
97 This method is used by the \fBoo::object\fR command to copy the state of one
98 object to another. It is responsible for copying the procedures and variables
99 of the namespace of the source object (\fIsourceObjectName\fR) to the current
100 object. It does not copy any other types of commands or any traces on the
101 variables; that can be added if desired by overriding this method in a
102 subclass.
103 .VE
104 .SH EXAMPLES
105 .PP
106 This example demonstrates basic use of an object.
107 .PP
108 .CS
109 set obj [\fBoo::object\fR new]
110 $obj foo             \fI\(-> error "unknown method foo"\fR
111 oo::objdefine $obj method foo {} {
112     my \fBvariable\fR count
113     puts "bar[incr count]"
114 }
115 $obj foo             \fI\(-> prints "bar1"\fR
116 $obj foo             \fI\(-> prints "bar2"\fR
117 $obj variable count  \fI\(-> error "unknown method variable"\fR
118 $obj \fBdestroy\fR
119 $obj foo             \fI\(-> error "unknown command obj"\fR
120 .CE
121 .SH "SEE ALSO"
122 my(n), oo::class(n)
123 .SH KEYWORDS
124 base class, class, object, root class
125 .\" Local variables:
126 .\" mode: nroff
127 .\" fill-column: 78
128 .\" End: