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 object obj that it's invoked upon, and it invokes any destructors on the object's class while it's at it. it is equivalent to using rename to 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 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.

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 method methodName on object obj fails. the arguments that the user supplied to the method are given as arg arguments. if methodName is 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 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. it's basically the "who dis" auto-reply. πŸ’€
  • 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. 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. 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. it's the "where exactly do you live" of variables. 🏠
  • obj <cloned> sourceObjectName β€” this method is used by the oo::object command 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