Chapter 8 examined decorators, which are wrappers that implement the same interface as the object they wrap. This chapter examines composite objects. A composite object is similar to a decorator except that it wraps multiple objects, each of which implements the same interface as itself. This seemingly small distinction makes a big difference in the structure of a composite and how it is used. Composite objects correspond to trees and composite methods tend to involve tree traversals.
This chapter presents three examples of composites: predicates, graphical user interfaces (GUIs), and cookbook recipes. These ...