Factory Pattern
Updated 2026-07-30
Summary
In object-oriented programming, the factory method pattern is a design pattern that uses factory methods to deal with the problem of creating objects without having to specify their exact classes. Rather than by calling a constructor, this is accomplished by invoking a factory method to create an ob…
Definition
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Scaffold use: encapsulate change. In mental models, this means establishing an 'intermediate layer' to handle uncertainty. Do not directly depend on specific people or things (hard-coding), but rely on a 'generation mechanism'. When the environment changes, only the factory logic needs to be modified, without having to start over.
Introduction
How to use
Encapsulate change. In mental models, this means establishing an 'intermediate layer' to handle uncertainty. Do not directly depend on specific people or things (hard-coding), but rely on a 'generation mechanism'. When the environment changes, only the factory logic needs to be modified, without having to start over.
Mechanism
Define an interface for creating objects, deferring instantiation of concrete classes to subclasses or factory methods; the caller only depends on the abstract product, not the concrete implementation, thereby reducing coupling and encapsulating change points.
Practice
In progress 0/4Practice this model in one real situation:
Cases
- Cross-platform UI components return different button instances based on the system; business rule engines return different handlers based on configuration.
Common pitfalls
- Forcing a factory for every class leads to over-design; ignoring the cost of abstraction and abstracting prematurely where change points are unclear increases complexity.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Factory_method_patternverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS