Design Patterns Java™ Workbook

(Michael S) #1
Chapter 16. Factory Method

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 FACTORY METHOD 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 FACTORY METHOD 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

Free download pdf