9 The Factory Method and Abstract Factory Design Patterns

 

This chapter covers

  • The Factory Method Design Pattern
  • The Abstract Factory Design Pattern

Chapter 8 mentioned that applications development is about algorithms and data. The two design patterns in this chapter model the ways applications can deploy software factories to create objects during run time.

The Factory Method Design Pattern provides a model for creating a group of related objects. Our example application shows how the design pattern allows a school athletic department to delegate responsibilities to the varsity sports and intramural sports organizations. The Abstract Factory Design Pattern goes further and provides a model for creating families of objects, preventing mixing objects from different families. We’ll expand the example application to ensure that the varsity and intramural sports organizations keep their responsibilities apart.

In this chapter, we’ll develop another example application incrementally. We’ll adapt the appropriate patterns one at a time to model solutions to the architecture design problems as we encounter them.

NOTE

Be sure to read the introduction to part 4 for important information about design patterns in general and to learn how this and subsequent chapters teach each pattern.

9.1 The Factory Method Design Pattern lets subclasses create objects

9.1.1 Desired design features

9.1.2 Before using the Factory Method Design Pattern

9.1.3 After using the Factory Method Design Pattern

9.1.4 Factory Method’s generic model

9.2 The Abstract Factory Design Pattern creates families of objects

9.2.1 Before using the Abstract Factory Design Pattern

9.2.2 After using the Abstract Factory Design Pattern

9.2.3 Abstract Factory’s generic model

Summary