PrepZone Logo
PrepZone

When to Use Which Pattern

A decision guide — not a catalogue to memorise.

Why this matters

  • Creation logic scattered → Factory or Abstract Factory
  • Incompatible interface → Adapter
  • Algorithm varies → Strategy
  • Do not name five patterns in the first five minutes
  • Patterns are forces and solutions — name the force before the pattern.
Creational
Factorychoose implementation
Builderstep-by-step assembly
Structural
Decoratorstack behaviour
Facadesimple entry point
Behavioral
Strategyswap algorithm
Observernotify subscribers
Statebehaviour by mode
Pick the family first, then the specific pattern.

Overview

A decision guide — not a catalogue to memorise. Study each section below in order — every list is interview-ready reference material.

Creational forces

Points to cover

  • Creation logic scattered → Factory or Abstract Factory
  • Many optional constructor params → Builder
  • Exactly one instance needed → Singleton (prefer DI scope instead)
  • Family of related products → Abstract Factory

Structural forces

Points to cover

  • Incompatible interface → Adapter
  • Add behaviour without subclass explosion → Decorator
  • Simplify complex subsystem → Facade
  • Tree structures → Composite

Behavioral forces

Points to cover

  • Algorithm varies → Strategy
  • Notify many on change → Observer
  • Undo/redo → Command
  • Mode changes behaviour → State
  • Fixed steps, varying details → Template Method

Anti-pattern: pattern fever

Points to cover

  • Do not name five patterns in the first five minutes
  • Introduce pattern when force appears, not preemptively
  • Simpler design beats clever pattern stack
Java
// CampusOS — apply "Creational forces" on paper first, then in code
public final class PatternSelectionGuideExample {
    // 1. Name entities from the problem statement
    // 2. Draw relationships before writing methods
    // 3. Introduce patterns only when a force appears
}

Quick recall

Everything you need if you only revisit this box.

  1. Creational forces — review this slice before mock interviews.
  2. Structural forces — review this slice before mock interviews.
  3. Behavioral forces — review this slice before mock interviews.
  4. Anti-pattern: pattern fever — review this slice before mock interviews.

Test yourself

Answer these before moving on — recall is what makes it stick.