Java Reference
In-Depth Information
The diagram also indicates that classes in the
MachinePlanner
hierarchy accept a
Machine
object in their constructors. This allows the planner to interrogate the object it is
planning for, regarding such criteria as the machine's location and the amount of material it is
currently processing.
SOLUTION 16.7
A
createPlanner()
method for the
Fuser
class might look like:
public MachinePlanner createPlanner()
{
return new BasicPlanner(this);
}
For
StarPress
, the
createPlanner()
method might be:
public MachinePlanner createPlanner()
{
return new StarPressPlanner(this);
}
These methods shows the F
ACTORY
M
ETHOD
pattern at work. When we need a planner
object, we call the
createPlanner()
message of the ma-chine we want to plan for.
The specific planner that we receive depends on the machine.