Summary

The Abstract Factory is used when you must coordinate the creation of families of objects. It gives a way to take the rules regarding how to perform the instantiation out of the client object that is using these created objects.

  • First, identify the rules for instantiation and define an abstract class with an interface that has a method for each object that needs to be instantiated.

  • Then, implement concrete classes from this class for each family.

  • The client object uses this factory object to create the server objects that it needs.

Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.