Introduction

Toe is an extension to the Tcl programming language that enables object-oriented (OO) programming in a class-based, Java-like style. Toe provides commands that allow a Tcl scripting programmer to create OO classes, define functional relationships between classes, run Tcl code in objects created from the classes, and implement various multiple-class patterns that are well-known in the object-oriented paradigm.

The primary purposes of Toe are:

  1. to provide a complete and integrated body of functionality for rich OO programming in a style that approximates what Java and C++ offer,
  2. to enable an uncoupling of software design and implementation in Tcl, and
  3. to leverage the Tcl/Tk environment as much as possible.
The distinctive features of Toe to Tcl users include object ownership and lifetime management, interfaces as sets of method declarations, and a framework-enabling abstraction mechanism for calling methods in a derived class from a method in the base class. In combination with classes themselves, these features facilitate the implementation of many design patterns in Tcl. [1], [2], [3], [4].

The programming model for Toe is similar to that for the Java and C++ programming languages. In Toe, a class is provided as an essentially complete specification of behavior and data to be instantiated as one or more objects, in which the values of class variables become unique to that object.

Compared to other OO systems on the Tcl platform, Toe shares many features, but differs in its foundation. Toe maintains an internal representation for each class specification, and integrates a class with other components to instantiate an object. Toe provides a partially exposed "runtime" for managing classes and objects, and for supporting introspection. Toe also provides a unique, "common" object for each class solely to contain the data and methods that are declared "common," akin to "static" in Java or C++. Toe allows, but does not encourage, the modification of instantiated objects. Toe also extends the use of Java-like interfaces, in that a class in Toe can either implement or abstract an interface containing method declarations. (see comparison chart)

If you are comfortable programming in Tcl, but would like to realize the benefits of OO programming in the class-based style of other popular OO languages, then Toe may be your easiest option. If, for professional or personal reasons, you program in multiple languages, and Java, C++, or Objective-C are among those languages, then you may find that Toe enables you to use your OO knowledge base for programming in like manner in a Tcl environment.

Features

The high-level feature set for Toe includes the following:

  • Support for four desirable characteristics of object-oriented programming: abstraction, (data) encapsulation, inheritance, polymorphism
  • Feature similarities with ITcl, XOTcl, and Java
  • Inner (nested) classes
  • "public" "protected" and "private" access control, as in Java and C++, for variables and methods
  • Separate objects for separate scopes of executable code:
    • Dynamic objects (instances)
    • A single common ("static") object
    • A Tcl command for each object
  • Direct access from dynamic objects to the variables of the common object, for a given class
  • Interfaces, as specifications of methods to be implemented in, or abstracted by, a class
  • Interfaces, as weak "types," with support for type checking
  • Two forms of inheritance by a class:
    • single class inheritance for dynamic instances
    • multiple interfaces (simlar to Java interfaces)
  • Support for OO frameworks that include inversion of control
  • Mixins (methods and filters) to add or modify methods within a class or object
  • Method overriding
  • Class constructor and destructor, implicit if not explicit
  • Object ownership:
    • implicit ownership of a new instance by the object within which the instance is created
    • programmatic transfer of object ownership (facilitating collection classes, and object pools)
  • Garbage prevention:
    • "Owned" objects are deleted automatically when the owning object is deleted
    • Objects created within a method may optionally be local to that method, and deleted upon method completion
  • Introspection:
    • "my" "self" and "next" commands within each object, modeled after their namesakes in TclOO
    • Additional runtime commands for introspection
  • Object recycling, as an alternative to object replacement
  • Rootless native hierarchy (no "Object" base class)
  • Dynamic revision of classes, objects, interfaces and mixins
  • Programmable policy settings that affect runtime behavior
  • Implemented in pure Tcl (only dependency: package require Tcl 8.5)