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:

This method destroys the object, obj, that it is invoked upon, invoking any destructors on the object’s class in the process. It is equivalent to using rename to delete the object command. The result of this method is always the empty string.

The oo::object class supports the following non-exported methods:
eval ?arg ...?

This method concatenates the arguments, arg, as if with concat, and then evaluates the resulting script in the namespace that is uniquely associated with obj, returning the result of the evaluation.

obj unknown ?methodName? ?arg ...?

This method is called when an attempt to invoke the method methodName on object obj fails. The arguments that the user supplied to the method are given as arg arguments. If │ methodName 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 oo::object class) generates a suitable error, detailing what methods the object supports given whether the object was invoked by its public name or through the my command.

obj variable ?varName ...?

This method arranges for each variable called varName to be linked from the object obj’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 varName argument must not have any namespace separators in it. The result is the empty string.

obj varname varName

This method returns the globally qualified name of the variable varName in the unique namespace for the object obj.

obj <cloned> sourceObjectName

This method is used by the oo::object 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 │ (sourceObjectName) 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.


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"


my(n), oo::class(n)


base class, class, object, root class


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.