9 The Factory Method and the 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 ways applications can become more flexible by deploying 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 and prevents mixing objects from different families. We’ll expand the example application to ensure that the varsity sports and intramural sports organizations keep their responsibilities apart from each other.

In this chapter, we’ll again develop the 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.

Learning about design patterns

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 Factory Method

9.1.3 After using Factory Method

9.1.4 Factory Method’s generic model

9.2 The Abstract Factory Design Pattern creates families of objects

9.2.1 Before using Abstract Factory

9.2.2 After using Abstract Factory

9.2.3 Abstract Factory’s generic model

9.3 Summary