O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required