Resources regarding TCL-OO (Object Oriented Programming in TCL)

I do my internship, and the internship requires the study and practice of TCL - OO, so I hunted for textbooks, examples, TCL - OO books, but I can not find anything, so I would really appreciate if anyone could give me good advice regarding TCL - OO.

I did some research online and came across these materials.

Links: http://www.tcl.tk/cgi-bin/tct/tip/257

Book: TCL / TK Developer's Guide 3rd edition of the Flynt cliff - has only 2 chapters on TCL - OO

so besides these two links, if anyone could direct me with additional material, that would be great. thanks in advance

+4
source share
3 answers

You have a link to the new OO support, which is part of Tcl 8.6, which is still under development, the resources of this OO subsystem will probably be harder to find, and although they can be used, since I believe that it is aimed more like basis for other OO packages.

For Tcl 8.5 and earlier, there are a number of โ€œadditionsโ€ to OO packages, a good starting point here . I have used both incr_Tcl and XOTcl in the past, and you should be able to find a reasonable amount of information on both of them, their home pages have online manuals, tutorials and examples.

+3
source

Disclosure: I wrote TclOO (with a lot of help from others in development and testing).


Simple start

TclOO allows for very simple use, but can become extremely complex when you start using most of its functions. Here is an example:

# Make a class oo::class create Example { variable x ;# Not the same as [variable] in a namespace! constructor {} { set x 1 } method bar {} { return [incr x] } } Example create foo ;# Make an instance puts [foo bar] ;# Call the instance to get 2 puts [foo bar] ;# Call the instance to get 3 puts [foo bar] ;# Call the instance to get 4 foo destroy ;# Kill the instance 

Writing a class is pretty simple, and the above gives you enough to do a lot. There are several main functions that are not listed: superclass allows you to name the parent class of the class, by default it is oo::object , which is the class of all objects; forward allows you to send a method call to another command, simple delegation; destructor allows you to write what is called when the object leaves; execution of Example new will make the object without its name, the name of the created object is the result of its call; the name of the current object is the result of calling self inside the method.

Constructors and methods can take arguments in the same way as the main Tcl proc . Destructors cannot.

More difficult

Objects can be rename d, like any other Tcl command, and a whole host of introspections are available for them under the info object and info class . You can attach special behavior for each object using oo::objdefine . Each object has a private namespace that you can use to store state in (where is the variable x in the above example).

Methods are not exported by default unless their name begins with a lowercase letter (strictly, it depends on whether it matches the ball pattern " [az]* "). You can change this if you want.

Classes themselves are objects (instances of oo::class ), so they are created by calling oo::class create ; their constructor passes the script that you provide to the oo::define command, which is responsible for determining the behavior of the classes. The create and new methods are as follows: methods on classes that create instances of these classes (with / without name, respectively).

You can use multiple inheritance. And mixins. And filters. And add a submit handler to deal with attempts to call an unknown method.

You can subclass oo::class yourself so that you can define new ways to create and manage objects.

You can change the class of any object at runtime (except oo::object and oo::class , they are specially locked for sanity reasons).

...

Yes, I am the author of TclOO, but I'm still learning what my creation can do. I tried very hard to make sure that you will do almost everything that you ask about it.

+4
source

A little late, but ...

There is a tutorial that I posted at http://www.magicsplat.com/articles/oo.html

+4
source

All Articles