Card 05/ 05

RecapDifficulty: Advanced1 min

Recap: Choosing a Creational Pattern

Ask what varies in the creation, and reach for a pattern only when something does.

Each creational pattern lets one thing about creation vary, so the choice starts by naming what varies.

  • Factory Method. The class of one product varies, and a subclass decides it.
  • Abstract Factory. A family of products varies together, and one factory object guarantees they match.
  • Builder. The parts and order of one complex product vary, and the build step checks the result once.
  • Prototype. New objects start as copies of a configured one, because set-up is costly or the class is unknown.
  • Singleton. Exactly one instance may exist; passing one object in often gives the same guarantee without global state.
  • The constructor. When nothing varies, it is the design. Add a pattern when a second variant arrives, not before.