Java Reference
In-Depth Information
CHALLENGE 16.6
Fill in the diagram of a
Machine
/
MachinePlanner
parallel hierarchy in
Figure 16.3.
Figure 16.3. Slim down the
Machine
hierarchy by moving planning logic to a
parallel hierarchy.
CHALLENGE 16.7
Suppose that you make the
Machine
class abstract and add an abstract method
createPlanner()
. Write a
createPlanner()
method for the
Fuser
and
StarPress
classes.
Summary
The intent of the F
ACTORY
M
ETHOD
pattern is to define the interface for creating a new
object so that a service provider decides which class to instantiate instead of clients. This
pattern occurs in the Java class libraries and is common in application code.
You can also apply F
ACTORY
M
ETHOD
when you want to introduce a parallel class hierarchy.
This can help keep a set of classes from becoming bloated with many different aspects of