Chapter    9

The Factory Method Pattern

The factory method pattern is used when there is a choice to be made between classes that implement a common protocol or share a common base class. This pattern allows implementation subclasses to provide specializations without requiring the components that rely on them to know any details of those classes and how they relate to each other. Table 9-1 puts the factory method into context.

Table 9-1. Putting the Factory Method Pattern into Context

Question

Answer

What is it?

The factory method pattern selects an implementation class to satisfy a calling component’s request without requiring the component to know anything about the implementation classes or the way they relate to one another.

What are the benefits? ...

Get Pro Design Patterns in Swift 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.