Version 2 of itcl internals

Updated 2008-10-04 12:39:20 by apw

This page is intended for collecting some of the internals of itcl for being able to discuss some wanted enhancements in Tcl core for use by itcl.

At the moment I apw am just dumping my ideas and I will clean that up later on.

Classes in itcl always handled as namespaces, that means every class in itcl corresponds to a namespace with the same name.

Example (with empty class body):

::itcl::class cl1 { }

::itcl::class cl2 {

  inherit cl1

}

::itcl::class cl3 {

  inherit cl2

}

will create a namespace (and a class) ::cl1, ::cl2 and ::cl3

The inherit command determines how the class hierarchy is built. In the above case cl3 inherits cl2 (has a "superclass" cl2) and cl2 inherits cl1.

This is mostly equivalent with setting namespace path to: cl3, cl2, cl1.

Methods in itcl classes are similar to procs with the difference, that they only can be called from an object created for a class and they have a protection level (see below).

It is also possible to have procs in a class, these procs can be called like procs in a namespace depending on the protection level.

Variables in itcl classes are similar to namespace variables with the difference, that they only can be accessed from an object created for a class when calling a method and they have a protection level (see below).

Commons in itcl classes are similar to namespace variables and they can be accessed like namespace variables depending on the protection level. So the lookup of methods and variables is done starting in namespace cl3, then cl2 and then cl1.

As every method in itcl is called in the namespace of its class lookup for variables and methods for a method in class cl2 starts in cl2 and continues in cl1.

A method in cl3 starts lookup in cl3, then cl2 and then cl1.

Protection levels:

Itcl has 3 protection levels: Public, protected and private.

public protection level allows to access a variable from every method or proc tied to an itcl object and from the outside using the special methods configure and cget of an itcl object.

protected protection level allows to access a variable from every method or proc tied to an itcl object in the class where it is defined and in all derived classes.

private protection level allows to access a variable from every method or proc tied to an itcl object only in the class where it is defined.

The same definition as for variables holds for commons with the difference, that instead of an object the class(namespace) must be used.