March 2002
Intermediate to advanced
496 pages
8h 51m
English
| SOLUTION 5.1 | One answer is that Design Patterns (Gamma et al. 1995) shows Component as an abstract class, so Java developers may implement it that way without considering the use of a Java interface. Another answer is that the Component superclass often has fields and methods that its subclasses can share. For example, the Component class may have a name instance variable and a concrete toString() method that uses it. |
| SOLUTION 5.2 | For the Machine class, getMachineCount() should be something like:
public int getMachineCount()
{
return 1;
}
The class diagram shows that MachineComposite uses a List object to track its components. To count the machines in a composite, you might write: public int getMachineCount() { int count ... |
Read now
Unlock full access