Navigation Logo Creating Tcl Objects in C/C++ Navigation Logo

 

 

Object action families, such as those associated with Tk widgets or Tcl interpreters, are a form of object-orientation that is available in Tcl. For the Tcl/Tk programmer, this form of object orientation is a little like being able to use some C++ classes without being able to implement any such classes.

This chapter is about how to implement such classes. This is something you need the C/C++ connection to accomplish. The chapter begins with a discussion of object orientation in C rather than C++. This is because it is C's form of object orientation that supports that of Tcl.

The chapter continues with an example that extends Tcl with a stack data type.

Not everything that is objectlike should be implemented as an object. This is because some objectlike entities reproduce often and have short lives. Such entities have been called flyweight objects in the literature. Flyweight objects demand too much of the normal overhead that goes with object creation and destruction. The chapter would be incomplete without a discussion of how to put flyweight objects into your extensions.

The final section considers situations in which commands must work with multiple objects at once. These situations can be handled with either objects or flyweight objects. This happens to be the section in which the implementation of flyweight objects is described. The example extends Tcl with a vector data type.

All of the major examples in this section could be string-based or object-based. However, only the flyweight vectors are shown both ways. The other two major examples are one of each.

Remark

In this chapter, when the word "object" is used without any qualification, the context is assumed to be that of object-orientation and not of the Tcl_Obj data type.

  • Object Orientation in C
  • Object Orientation in Tcl
  • Implementing Object Actions
  • Implementing Class Actions
  • Commands that Work with Multiple Objects
  • Solutions to Exercises
 

 

[Sample TK Application]
Author's Home Page
Navigation Logo [Book's Cover]
Order from Amazon.