Version 21 of Simple class/object commands

Updated 2003-03-16 02:06:40

The following code is somewhat experimental. I have seen quite a few variations on this theme. However, I believe this code does things in a new and interesting way. This code is not feature complete, it is primarily a proof of concept at this point. Please feel free to make comments and/or criticize this code. If you have feature/code suggestions please feel free to add them to this page. If you would like to submit code changes, please email them to me and I will review them for addition.

This code allows for the following concepts/constructs:

  • "classes" definitions or "what procs and variables do all instances of this class have?"
  • "objects" or "an instance of a class."
  • Now supports transparent usage of class variables and procs from inside the class.
  • "interfaces" or "what procs are required to implement this interface?"
  • "comment" blocks inside class and interface declarations.
  • "single inheritance" or "procs from this other class are now in this class."
  • "multiple inheritance" or "procs from these other classes are now in this class."
  • "nested inheritance" or "procs from the base of my base are now in this class."
  • "constructors" and "destructors", that can take parameters and can prevent the object from being created/destroyed.

This code is now too big for a WiKi page (about 100K, including test files).

It may be downloaded from: http://www.tclbridge.com/tcl_oo.zip


Written By Joe Mistachkin

 Version History
  • 19/Nov/2002 Version 1.00 -- initial release
  • 19/Nov/2002 Version 1.20 -- added transparent access to class variables
  • -- streamlined some of the code
  • -- more comprehensive cleanup of variables, procs, and namespaces
  • 20/Nov/2002 Version 1.25 -- more robust handling of invalid class declarations
  • -- added tests for arrays inside classes
  • 20/Nov/2002 Version 1.30 -- more argument validation
  • -- added more tests dealing with invalid class declarations
  • -- added class_objects proc to return a list of active objects for a class
  • 20/Nov/2002 Version 1.31 -- fixed error handling for a certain test case involving bad class declarations
  • 20/Nov/2002 Version 1.32 -- fixed problem preventing multiple matches in class_objects
  • 22/Nov/2002 Version 1.40 -- added support for interfaces
  • -- added support for comment blocks inside classes and interfaces
  • -- cleaned up and organized tests
  • -- changed some error messages
  • -- other miscellaneous changes
  • 13/Mar/2003 Version 1.60 -- added support for inheritance, single and multiple
  • -- a lot of cleanup and reorganization
  • -- added support for implementing an interface using base classes
  • -- added more introspection features
  • -- added support for parameterized constructors/destructors (can stop creation/destruction)
  • 13/Mar/2003 Version 1.61 -- corrected loop invariant for interface definitions
  • 15/Mar/2003 Version 1.75 -- massive internal changes to namespace handling
  • -- added support for nested inheritance
  • -- added first stages of "conflict resolution" (currently, there is none)
  • -- cleaned up class_hasProc
  • -- massively changed and streamlined class_findProc
  • -- added more introspection commands
  • -- added more tests to class_test2.tcl

Category Object Orientation