Design Patterns Java™ Workbook

(Michael S) #1

Chapter 17. Abstract Factory....................................................................................................................


Chapter 17. Abstract Factory


Sometimes, you want to provide for object creation while retaining control of which class to
instantiate. In such circumstances, you can apply the FACTORY METHOD pattern with
a method that uses an outside factor to determine which class to instantiate. The outside factor
can be anything. In Chapter 16, Factory Method, this factor was the status of an online credit
agency. Sometimes, the factor that controls which object to instantiate can be thematic,
running across several classes. The ABSTRACT FACTORY pattern addresses this situation.
The intent of this pattern is to provide for the creation of a family of related, or dependent,
objects.


Abstract Factories for Families of Objects.............................................................................................


To answer the challenges in Chapter 16, you designed a pair of classes to implement
the CreditCheck interface. Your design isolates other developers from knowing whether
the credit agency is up and running. Suppose that in supporting the verification of customer
information, you add a couple of classes that check the status of a customer's billing and
shipping addresses. Your package of checking services looks like Figure 17.1.


Figure 17.1. Classes in this package check a customer's credit, shipping address, and
billing address.
Free download pdf