Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M0531

Factory Pattern

Factory Pattern
StructureHigh supportLogic
Included
account_tree

Updated 2026-07-30

Loading revision record…

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.

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/4

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

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.

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Factory_method_patternZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS