<h1>oo::class</h1>
<DL style="font-size: .85em">
<DD><A HREF="#M2" NAME="L182">NAME</A>
<DL><DD>oo::class &mdash; class of all
<DD><A HREF="#M3" NAME="L183">SYNOPSIS</A>
<DL>
</DL>
<DD><A HREF="#M4" NAME="L184">CLASS HIERARCHY</A>
<DD><A HREF="#M5" NAME="L185">DESCRIPTION</A>
<DD><A HREF="#M6" NAME="L186">CONSTRUCTOR</A>
<DD><A HREF="#M7" NAME="L187">DESTRUCTOR</A>
<DD><A HREF="#M8" NAME="L188">EXPORTED METHODS</A>
<DL class="exported methods">
<DD><A HREF="#M9" NAME="L189"><I>cls </I><B>create </B><I>name </I>?<I>arg
<DD><A HREF="#M10" NAME="L190"><I>cls </I><B>new </B>?<I>arg
</DL>
<DD><A HREF="#M11" NAME="L191">NON-EXPORTED METHODS</A>
<DL class="non-exported methods">
<DD><A HREF="#M12" NAME="L192"><I>cls name nsName</I> ?<I>arg
</DL>
<DD><A HREF="#M13" NAME="L193">EXAMPLES</A>
<DD><A HREF="#M14" NAME="L194">SEE ALSO</A>
<DD><A HREF="#M15" NAME="L195">KEYWORDS</A>
</DL>
<H3><A
<b>oo::class</b> &mdash; class of all classes
<H3><A
package require TclOO<BR>
<BR>
<B>oo::class</B><I> method </I>?<I>arg ...</I>?<BR>
<H3><A NAME="M4">CLASS
<B><A
   <font size="+1">&#8594;</font> <B>oo::class</B><BR>
<H3><A
Classes are objects that can manufacture other objects according to a pattern
stored in the factory object (the class). An instance of the class is created
by calling one of the class's factory methods, typically either <B>create</B>
if an explicit name is being given, or <B>new</B> if an arbitrary unique name
is to be automatically selected.
<P>
The <B>oo::class</B> 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 <B><A so every class is also an object.
Additional metaclasses (i.e., classes of classes) can be defined if necessary
by subclassing <B>oo::class</B>. Note that the <B>oo::class</B> object hides the
<B>new</B> method on itself, so new classes should always be made using the
<B>create</B> method.
<H4><A
The constructor of the <B>oo::class</B> class takes an optional argument which,
if present, is sent to the <B><A command (along with the name of
the newly-created class) to allow the class to be conveniently configured at
creation time.
<H4><A
The <B>oo::class</B> 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.
<H4><A NAME="M8">EXPORTED
<DL class="exported methods">
<DT><A NAME="M9"><I>cls </I><B>create </B><I>name </I>?<I>arg
This creates a new instance of the class <I>cls</I> called <I>name</I> (which is
resolved within the calling context's namespace if not fully qualified),
passing the arguments, <I>arg ...</I>, to the constructor, and (if that returns
a successful result) returning the fully qualified name of the created object
(the result of the constructor is ignored). If the constructor fails (i.e.
returns a non-OK result) then the object is destroyed and the error message is
the result of this method call.
<P><DT><A NAME="M10"><I>cls </I><B>new </B>?<I>arg
This creates a new instance of the class <I>cls</I> with a new unique name,
passing the arguments, <I>arg ...</I>, to the constructor, and (if that returns
a successful result) returning the fully qualified name of the created object
(the result of the constructor is ignored). If the constructor fails (i.e.,
returns a non-OK result) then the object is destroyed and the error message is
the result of this method call.
<P>
Note that this method is not exported by the <B>oo::class</B> object itself, so
classes should not be created using this method.
<P></DL>
<H4><A NAME="M11">NON-EXPORTED
The <B>oo::class</B> class supports the following non-exported methods:
<P>
<DL class="non-exported methods">
<DT><A NAME="M12"><I>cls name nsName</I> ?<I>arg
This creates a new instance of the class <I>cls</I> called <I>name</I> (which is
resolved within the calling context's namespace if not fully qualified),
passing the arguments, <I>arg ...</I>, to the constructor, and (if that returns
a successful result) returning the fully qualified name of the created object
(the result of the constructor is ignored). The name of the instance's
internal namespace will be <I>nsName</I> unless that namespace already exists
(when an arbitrary name will be chosen instead). If the constructor fails
(i.e., returns a non-OK result) then the object is destroyed and the error
message is the result of this method call.
<P></DL>
<H3><A
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.
<P>
<PRE><B>oo::class create</B> fruit {
    method eat {} {
        puts &quot;yummy!&quot;
    }
}
<B>oo::class create</B> banana {
    superclass fruit
    constructor {} {
        my variable peeled
        set peeled 0
    }
    method peel {} {
        my variable peeled
        set peeled 1
        puts &quot;skin now off&quot;
    }
    method edible? {} {
        my variable peeled
        return $peeled
    }
    method eat {} {
        if {![my edible?]} {
            my peel
        }
        next
    }
}
set b [banana <B>new</B>]
$b eat               <I><font size="+1">&#8594;</font> prints &quot;skin now off&quot; and &quot;yummy!&quot;</I>
fruit destroy
$b eat               <I><font size="+1">&#8594;</font> error &quot;unknown
<H3><A NAME="M14">SEE
<B><A <B><A
<H3><A
class, metaclass, object