7.5.1 Decorator Pattern (pp.201-202)
The link between the Decorator Pattern and discrimnated unions seems a bit tenuous.
[Expert F# p.67]
"
Note Discriminated unions are a powerful and important construct and are useful when modeling a finite,
sealed set of choices. ... They are by design,
nonextensible: subsequent modules cannot add new cases to a discriminated union. This is deliberate: you get strong and useful guarantees by placing a limit on the range of possible values for a type. Extensible types can be defined through the use of records of functions and object interface types, discussed in Chapter 5 and Chapter 6."
The Decorator Pattern typically is applied in situations where the ConcreteComponent (object hierarchy) is closed to modification (that is, sealed) and we desperately need to extend it (later - possibly dynamically).
So there doesn't seem to be much of an overlap in the intent of the two constructs.
Furthermore it is questionable whether TitledPart is in fact a decorator - it is more likely just another type of CompositeComponent (as there is no restriction on the number of different classes that can act as CompositeComponents). In the XML the title text could have just as easily been placed in a child element to the titled element rather than an attribute value (how do you italicize a single word in the title if it is stuck in an attribute?). While the TitledPart could be viewed as "decorating" the contained TextPart, it can also be viewed (especially looking at the document) as vertical SplitPart were the first TextPart has a larger font and shorter text than the next. So the TitledPart isn't actually needed unless you want to identify the title text as such.
If the point is to show that the (object-oriented) problems that many GoF patterns solve intrinsically do not occur in functional language programming, ala
Functional Programming For The Rest of Us:
"In a functional language one does not need design patterns because the language is likely so high level, you end up programming in concepts that eliminate design patterns all together."
then that may be best relegated to an appendix.
(
Does Functional Programming Replace GoF Design Patterns?
Peter Norvig: Design Patterns in Dynamic Programming)
Message was edited by: tempusfugit