Version 3 of Design patterns in Tcl

Updated 2001-10-09 17:00:47

Richard Suchenwirth - Design patterns have been made famous by the book "Design Patterns. Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (The Gang of Four). A short list of the 23 patterns in that book is at http://wiki.cs.uiuc.edu/PatternStories/DesignPatterns

Most patterns assume OO approaches, inheritance, etc., and thus are more suited for Incr Tcl design patterns. But some can be done in pure Tcl, or are used in the Tcl implementation. Let's brainstorm...

  • Chain of responsibility: We can have that effect with
 rename existingName _otherName
 proc existingName {...} {
    # do the special stuff, eventually:
    _otherName
 }

See Overloading widgets, Guarded proc for concrete examples.

  • Command: Not sure (especially on the "undo" aspect), but isn't the following already a simple implementation?
 set cmd [list keyword arg arg...]
 # some time later:
 eval $cmd
  • Flyweight: Re-use of small objects from a pool, so distinct objects are only created once, and referred to later. Used since 8.4 in the C implementation of split $string "". AFAIK also somewhere in the binary scan command.