itcl chain

The actual command is 'chain'; I think this page will be found more easily with the title itcl chain.

Chain is used in itcl::class objects with inheritance and Derived itcl::class. In an inherited class, a method may be written that calls the parent class method of the same name; the safest way to do this is with the chain command. This is useful if you change the class inherited from then chain will automatically call the new class. Extending the code of Derived itcl::class by one chain command:

   package require Itcl
  itcl::class helloworld {
    public variable owner "No-one"

    method greet {} { puts "Hello World from $owner" }
  }
  itcl::class goodbyeworld {
    inherit helloworld

    method greet {} { puts "Goodbye Cruel World from $owner and " 
        chain
   }
  }
  helloworld  h1
  goodbyeworld h2
  h1 configure -owner Me
  h2 configure -owner You
  h1 greet
==>Hello World from Me
   h2 greet
==>Goodbye Cruel World from You and 

==>Hello World from You

Note that both greet methods have been called for h2 (which inherits from helloworld).

An example of use - if you want to write the contents of a collection of objects to a file (eg to save from any serious project) then the writetofile method will want to use chain so that writetofile is called for all the classes inherited from, automatically writing the description of the inherited classes.

The chain command is quite similar to next in TclOO, XOTcl and NX.