Recursive Behavior in Composites

Engineers at Oozinoz perceive a natural composition in the processing machines they use to produce fireworks. The factory is composed of bays; each bay has one or more manufacturing lines; a line is a collection of machines that collaboratively produce material to meet a schedule. The developers at Oozinoz have modeled this composition from the problem domain with the class structure shown in Figure 5.2. As the figure shows, the getMachineCount() behavior applies to both individual machines and collections of machines and returns the number of machines in any given component.

Figure 5.2. The getMachineCount() method is an appropriate behavior for both individual machines and composites.
CHALLENGE 5.2Write the ...

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.