An Ordinary Composite

Figure 5.1 shows an ordinary composite structure. The Leaf and Composite classes share a common interface that Component abstracts, and a Composite object retains a collection of other Composite and Leaf objects. Note that the Component class in Figure 5.1 is an abstract class with no concrete operations, so you could define it as an interface that Leaf and Composite implement.

Figure 5.1. The key ideas of Composite are that composites can contain other composites—not just leaves—and that composite and leaf nodes share a common interface.

CHALLENGE 5.1Give two reasons why the interface that Leaf and Composite share usually ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.