object(3tcl)
β¨ object β the root class of literally everything β¨
okay bestie, welcome to object(3tcl), one of the TclOO Commands π this is the manual page for oo::object, aka the mother of all classes, the blueprint of blueprints, the main character of the whole object hierarchy. sit down, grab a strawberry π, let's get into it.
π NAME π
oo::object β the root class of the class hierarchy. periodt.
πΈ SYNOPSIS πΈ
package require tcl::oo
oo::object method ?arg ...?
π¦ CLASS HIERARCHY π¦
oo::object
it's givingβ¦ top of the food chain. no parent. no ancestors. just vibes. β¨
π DESCRIPTION π
so the oo::object class is the root class of the object hierarchy β every single object is an instance of this class. every one. no exceptions. and because classes are themselves objects (yes, they're objects too, the recursion is real π), classes are instances of this class as well. objects are always referred to by their name, and they can be renamed while maintaining their identity β like a glow-up that doesn't change who you are fr fr.
you can make instances of objects with either the create or new methods of the oo::object object itself, or by invoking those methods on any of the subclass objects. if you want the full lore on that, go read oo::class. π
and the configuration of individual objects β i.e., instance-specific methods, mixed-in classes, etc. β is controlled with the oo::objdefine command. that's the customization station.
every object has a unique namespace associated with it, called the instance namespace. this namespace holds all the instance variables of the object, and it 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 gets deleted too β rip, gone, no crumbs. π«Ά
the instance namespace contains the object's my command, which you can use 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. iconic behavior honestly.
π§ CONSTRUCTOR π§
the oo::object class does not define an explicit constructor. it's lowkey minimal like that. β¨
π DESTRUCTOR π
the oo::object class does not define an explicit destructor either. no dramatic exit scene. it just goes. π
π EXPORTED METHODS π
the oo::object class supports the following exported methods:
obj destroyβ this method destroys the objectobjthat it's invoked upon, and it invokes any destructors on the object's class while it's at it. it is equivalent to usingrenameto delete the object command. the result of this method is always the empty string. always. no cap. π
π NON-EXPORTED METHODS π
the oo::object class supports the following non-exported methods:
obj eval ?arg ...?β this method concatenates the argumentsargas if withconcat, and then evaluates the resulting script in the namespace that is uniquely associated withobj, returning the result of the evaluation.
note that object-internal commands such as my and self can be invoked in this context. iykyk. β¨
obj unknown ?methodName? ?arg ...?β this method gets called when an attempt to invoke the methodmethodNameon objectobjfails. the arguments that the user supplied to the method are given asargarguments. ifmethodNameis absent, that means the object was invoked with no method name at all (or any other arguments). the default implementation β i.e., the one defined by theoo::objectclass β generates a suitable error, detailing what methods the object supports given whether the object was invoked by its public name or through themycommand. it's basically the "who dis" auto-reply. πobj variable ?varName ...?β this method arranges for each variable calledvarNameto be linked from the objectobj's unique namespace into the caller's context. so if it's invoked from inside a procedure, then the namespace variable in the object is linked to the local variable in the procedure. eachvarNameargument 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 variablevarNamein the unique namespace for the objectobj. it's the "where exactly do you live" of variables. πobj <cloned> sourceObjectNameβ this method is used by theoo::objectcommand to copy the state of one object to another. it's 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, and it does not copy any traces on the variables. those can be added if desired by overriding this method in a subclass. sneak peek at the customization menu, fr fr. π
π EXAMPLES π
this example demonstrates basic use of an object. watch it slay:
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"
the way that last line justβ¦ errors. π gone but not forgotten.
π₯ SEE ALSO π₯
my(3tcl), oo::class(3tcl)
go read those next bestie, they're part of the same universe. π«Ά
β KEYWORDS β
base class, class, object, root class
this has been object(3tcl) from TclOO, version 0.1 β the original page signs off down there in the corner with TclOO 0.1 object(3tcl), so consider this your cute little goodbye wave. ππ stay rooted, queen. πΈβ¨ </bold>
π¦ where this page comes from
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 2007-2008 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms