[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, from where the "Intent" phrases are quoted below. 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''': "Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it." 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''': "Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations." 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 '''Composite''': "Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly." Tcl: lists of lists... proc handleComposite c { if {[llength $c]>1} { foreach i $c { handleComposite $i } } else { #individual object handler } } '''Flyweight''': "Use sharing to support large numbers of fine-grained objects efficiently." 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 ""'' To some extent this idea is behind Tcl's "copy on write" strategy for sharing Tcl_Obj values as well. '''Iterator''': "Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation." We have that sort-of built-in for the major container kinds (lists and arrays): foreach i $list {...} foreach {key value} [array get A] {...} foreach key [array names A] {...} Alternatively there are the [[array]] subcommands: array anymore array donesearch array nextelement array startsearch '''Observer''': "Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. " Why, if that isn't trace variable X w {...} ---- [Arts and crafts of Tcl-Tk programming] - [Playing UML]