Java Reference
In-Depth Information
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.2
Write the code for the getMachineCount() methods implemented by Machine
and by MachineComposite .
Suppose that MachineComponent also needs the following methods:
Method Behavior
isCompletelyUp() Indicates whether all the machines in a component are in an "up" state
stopAll()
Directs all the machines in a component to stop processing
getOwners()
Returns a set of process engineers responsible for the machines in
a component
Return all the in-process material in a machine component
getMaterial()
The definition and operation of each method in MachineComponent is recursive. For
example, the count of machines in a composite is the sum of the counts of machines in its
components.
Search WWH ::




Custom Search