LISTING 6‐7: (continued)
case EXPRESSO: coffee = new Expresso();
case LATTE: coffee = new Latte();
For brevity, this chapter shows only a code snippet of the enum type CoffeeType that dei nes the
type of coffee and the dispenseDrink method of the concrete Coffee class.
The factory method pattern is straightforward and useful to implement, but in more complex systems,
you need to organize it. This problem leads you to a new pattern called the abstract factory pattern.
The abstract factory pattern is described in both the GoF book and Head First Design Patterns as
“provides an interface for creating families of related or dependent objects without specifying their
What abstract factories offer is the encapsulation of a group of factories and control over how the
client accesses them. This chapter does not go into all the details of how to implement abstract
factories but instead offers a brief introduction for basic understanding.
The abstract factory class diagram is shown in Figure 6-2.
FIGURE 6-2: As can be seen in the class diagram, you can use the abstract factory pattern to group existing
factories and encapsulate how you access them.