TclOO Package

Artifact [39be8b589a]
Login

Artifact 39be8b589a9dca4600ee4c450d235b87d242415c:

Wiki page [Doc: oo::object] by dkf 2016-09-17 10:50:34.
D 2016-09-17T10:50:34.603
L Doc:\soo::object
N text/x-markdown
U dkf
W 6784
<h1>oo::object</h1>
<DL style="font-size:.85em">
<DD><A HREF="#M2" NAME="L1271">NAME</A>
<DL><DD>oo::object &mdash; root class of the class hierarchy</DD></DL>
<DD><A HREF="#M3" NAME="L1272">SYNOPSIS</A>
<DL>
</DL>
<DD><A HREF="#M4" NAME="L1273">CLASS HIERARCHY</A>
<DD><A HREF="#M5" NAME="L1274">DESCRIPTION</A>
<DD><A HREF="#M6" NAME="L1275">CONSTRUCTOR</A>
<DD><A HREF="#M7" NAME="L1276">DESTRUCTOR</A>
<DD><A HREF="#M8" NAME="L1277">EXPORTED METHODS</A>
<DL class="exported methods">
<DD><A HREF="#M9" NAME="L1278"><I>obj </I><B>destroy</B></A>
</DL>
<DD><A HREF="#M10" NAME="L1279">NON-EXPORTED METHODS</A>
<DL class="non-exported methods">
<DD><A HREF="#M11" NAME="L1280"><I>obj </I><B>eval</B> ?<I>arg ...</I>?</A>
<DD><A HREF="#M12" NAME="L1281"><I>obj </I><B>unknown ?</B><I>methodName</I>? ?<I>arg ...</I>?</A>
<DD><A HREF="#M13" NAME="L1282"><I>obj </I><B>variable </B>?<I>varName ...</I>?</A>
<DD><A HREF="#M14" NAME="L1283"><I>obj </I><B>varname </B><I>varName</I></A>
<DD><A HREF="#M15" NAME="L1284"><I>obj </I><B>&lt;cloned&gt; </B><I>sourceObjectName</I></A>
</DL>
<DD><A HREF="#M16" NAME="L1285">EXAMPLES</A>
<DD><A HREF="#M17" NAME="L1286">SEE ALSO</A>
<DD><A HREF="#M18" NAME="L1287">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
oo::object &mdash; root class of the class hierarchy
<H3><A NAME="M3">SYNOPSIS</A></H3>
package require TclOO<BR>
<BR>
<B>oo::object</B><I> method </I>?<I>arg ...</I>?<BR>
<H3><A NAME="M4">CLASS HIERARCHY</A></H3>
<B>oo::object</B><BR>
<H3><A NAME="M5">DESCRIPTION</A></H3>
The <B>oo::object</B> 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 <B>rename</B>d while maintaining their identity.
<P>
Instances of objects may be made with either the <B>create</B> or <B>new</B>
methods of the <B>oo::object</B> object itself, or by invoking those methods on
any of the subclass objects; see <B><A HREF="class">oo::class</A></B> for more details. The
configuration of individual objects (i.e., instance-specific methods, mixed-in
classes, etc.) may be controlled with the <B><A HREF="define">oo::objdefine</A></B> command.
<P>
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 <B><A HREF="my">my</A></B>
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.
<H4><A NAME="M6">CONSTRUCTOR</A></H4>
The <B>oo::object</B> class does not define an explicit constructor.
<H4><A NAME="M7">DESTRUCTOR</A></H4>
The <B>oo::object</B> class does not define an explicit destructor.
<H4><A NAME="M8">EXPORTED METHODS</A></H4>
The <B>oo::object</B> class supports the following exported methods:
<P>
<DL class="exported methods">
<DT><A NAME="M9"><I>obj </I><B>destroy</B></A><DD>
This method destroys the object, <I>obj</I>, that it is invoked upon, invoking
any destructors on the object's class in the process. It is equivalent to
using <B>rename</B> to delete the object command. The result of this method is
always the empty string.
<P></DL>
<H4><A NAME="M10">NON-EXPORTED METHODS</A></H4>
The <B>oo::object</B> class supports the following non-exported methods:
<P>
<DL class="non-exported methods">
<DT><A NAME="M11"><I>obj </I><B>eval</B> ?<I>arg ...</I>?</A><DD>
This method concatenates the arguments, <I>arg</I>, as if with <B>concat</B>,
and then evaluates the resulting script in the namespace that is uniquely
associated with <I>obj</I>, returning the result of the evaluation.
<P><DT><A NAME="M12"><I>obj </I><B>unknown ?</B><I>methodName</I>? ?<I>arg ...</I>?</A><DD>
This method is called when an attempt to invoke the method <I>methodName</I> on
object <I>obj</I> fails. The arguments that the user supplied to the method are
given as <I>arg</I> arguments.
If <I>methodName</I> is absent, the object was invoked with no method name at
all (or any other arguments).
The default implementation (i.e., the one defined by the <B>oo::object</B>
class) generates a suitable error, detailing what methods the object supports
given whether the object was invoked by its public name or through the
<B><A HREF="my">my</A></B> command.
<P><DT><A NAME="M13"><I>obj </I><B>variable </B>?<I>varName ...</I>?</A><DD>
This method arranges for each variable called <I>varName</I> to be linked from
the object <I>obj</I>'s unique namespace into the caller's context. Thus, if it
is invoked from inside a procedure then the namespace variable in the object
is linked to the local variable in the procedure. Each <I>varName</I> argument
must not have any namespace separators in it. The result is the empty string.
<P><DT><A NAME="M14"><I>obj </I><B>varname </B><I>varName</I></A><DD>
This method returns the globally qualified name of the variable <I>varName</I>
in the unique namespace for the object <I>obj</I>.
<P><DT><A NAME="M15"><I>obj </I><B>&lt;cloned&gt; </B><I>sourceObjectName</I></A><DD>
This method is used by the <B>oo::object</B> command to copy the state of one
object to another. It is responsible for copying the procedures and variables
of the namespace of the source object (<I>sourceObjectName</I>) to the current
object. It does not copy any other types of commands or any traces on the
variables; that can be added if desired by overriding this method in a
subclass.
<P></DL>
<H3><A NAME="M16">EXAMPLES</A></H3>
This example demonstrates basic use of an object.
<P>
<PRE>set obj [<B>oo::object</B> new]
$obj foo             <I><font size="+1">&#8594;</font> error &quot;unknown method foo&quot;</I>
oo::objdefine $obj method foo {} {
    my <B>variable</B> count
    puts &quot;bar[incr count]&quot;
}
$obj foo             <I><font size="+1">&#8594;</font> prints &quot;bar1&quot;</I>
$obj foo             <I><font size="+1">&#8594;</font> prints &quot;bar2&quot;</I>
$obj variable count  <I><font size="+1">&#8594;</font> error &quot;unknown method variable&quot;</I>
$obj <B>destroy</B>
$obj foo             <I><font size="+1">&#8594;</font> error &quot;unknown command obj&quot;</I></PRE>
<H3><A NAME="M17">SEE ALSO</A></H3>
<B><A HREF="my">my</A></B>, <B><A HREF="class">oo::class</A></B>
<H3><A NAME="M18">KEYWORDS</A></H3>
base class, class, object, root class

Z c48c9648292393e0ba9e32f35aad03af