Java Reference
In-Depth Information
CHALLENGE 12.4
Fill in the constructors in Figure 12.2 to support a design that ensures that every
MachineComponent object has a responsible engineer.
Figure 12.2. How can constructors ensure that every MachineComponent
object has a responsible engineer?
By anchoring a chain of responsibility, you strengthen the object model and simplify the code.
Now you can implement the getResponsible() method of MachineComponent as:
public Engineer getResponsible()
{
if (responsible != null)
{
return responsible;
}
return parent.getResponsible();
}
Search WWH ::




Custom Search