Tips and tricks

The procedures that implement the methods of an object are accessible from its namespace. Each procedure has an additional argument, which is the this argument. Thus, instead of writing (using the example classes from the obstcl course):

  $bar configure -one 2
  $bar breakfast
you could write:
  namespace eval $bar "configure $bar -one 2"
  namespace eval $bar "breakfast $bar"

or

  namespace eval Bar "configure $bar -one 2"
  namespace eval Bar "breakfast $bar"
The second version is a little faster than the first; the third and about twice as fast. In either case, inheritance and virtual methods work properly with this calling method. In this example, the configure method has been inherited from Object, but is still called correctly. This would not be the case if you tried to do this:
  Bar::configure $bar -one 2
  Bar::breakfast $bar

The instance variables of an object are stored in a namespace with the name you gave the object. (Yes, there is also a procedure with this same name.) You can set or examine instance variables directly (if you must) by going, for example,

  namespace eval $bar info vars
and
  namespace eval $bar set two

If you need more insights into the internals of obstcl, look at the code. To see what it is doing with your method definitions, go

  puts [info args Foo::three]
  puts [info body Foo::three]

Happy objecting!