The Factory Pattern

archetype ManufacturingObject-Oriented Design

Categories: software-engineering

What It Brings

Call something a “factory” and you import the entire industrial worldview into object creation. A factory takes raw materials, follows a specification, and produces finished goods. The GoF Factory Method and Abstract Factory patterns map this onto software: a factory method takes parameters, follows a creation protocol, and returns finished objects.

Key structural parallels:

Where It Breaks

Expressions

Origin Story

The Factory Method and Abstract Factory patterns were codified in Design Patterns (1994) by Gamma, Helm, Johnson, and Vlissides. But the manufacturing metaphor for object creation predates the GoF book. Smalltalk programmers in the 1970s and 1980s already spoke of “factory methods” — class-side methods whose job was to produce properly initialized instances. The term felt natural because Smalltalk’s object model (everything is an object, objects are created by sending messages to classes) maps neatly onto the idea of placing an order with a manufacturer.

The GoF formalized two variants: Factory Method (let subclasses decide which class to instantiate) and Abstract Factory (produce families of related objects). Both lean heavily on the manufacturing metaphor to explain their intent, and both are among the most commonly used — and most commonly over-applied — patterns in the catalog. The phrase “factory pattern” has become so ubiquitous in developer vocabulary that many programmers use it without thinking about assembly lines at all, edging it toward dead-metaphor territory.

References

Related Mappings