CMD Guide
HomeOO & Low-Level DesignDesign Patterns Overview

Classification of Design Patterns

Classification of Design Patterns

The 23 classic patterns from the "Gang of Four" (GoF) book are not a flat list to memorise — they are organised along one axis that tells you what part of your design a pattern touches. Knowing the classification is the difference between reciting names and reaching for the right tool under interview pressure.

1. Intuition — why a classification exists

A pattern is a named, reusable solution to a recurring design problem. Once you have two dozen of them, you need a filing system, otherwise recall becomes brute-force. The GoF classify patterns by purpose: which design concern they address. Three concerns recur in almost every object-oriented system:

Those three concerns give the three families: Creational, Structural, and Behavioral. The intuition is that any design pain you feel usually maps cleanly to exactly one of them, so the classification is a fast index from symptom to candidate patterns.

2. Precise definition — the three families

Creational patterns abstract the instantiation process so a system is independent of how its objects are created, composed, and represented. Examples: Factory Method, Abstract Factory, Builder, Prototype, Singleton. Signal: you see sprawling new ConcreteX() or giant constructors and want to isolate the choice of concrete type.

Structural patterns describe how classes and objects are combined to form larger structures while keeping them flexible and efficient. Examples: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy. Signal: you need to make incompatible interfaces work together, add responsibilities, or simplify a subsystem — the emphasis is on composition.

Behavioral patterns characterise how objects distribute responsibility and communicate at runtime. Examples: Strategy, Observer, Command, State, Template Method, Chain of Responsibility, Iterator, Mediator, Visitor, Memento, Interpreter. Signal: the pain is in control flow, algorithm selection, or who-talks-to-whom, not in construction or wiring.

A second, orthogonal axis the GoF add is scope: whether the pattern operates on classes (relationships fixed at compile time via inheritance) or on objects (relationships established at runtime via composition, generally more flexible). Most patterns are object-scoped.

3. Concrete example — one problem, one pattern per family

Imagine a payment service. Watch how the same domain surfaces all three concerns, each answered by a different family.

// CREATIONAL (Factory Method): isolate the choice of concrete gateway
interface PaymentGateway { Receipt charge(long cents); }

abstract class GatewayFactory {
    abstract PaymentGateway create();          // subclasses decide the type
}
class StripeFactory extends GatewayFactory {
    PaymentGateway create() { return new StripeGateway(); }
}

// STRUCTURAL (Adapter): make a legacy API fit our interface
class LegacyPayPal { void sendPayment(double dollars) { /* ... */ } }
class PayPalAdapter implements PaymentGateway {
    private final LegacyPayPal legacy = new LegacyPayPal();
    public Receipt charge(long cents) {
        legacy.sendPayment(cents / 100.0);      // translate the call
        return new Receipt();
    }
}

// BEHAVIORAL (Strategy): swap the retry algorithm at runtime
interface RetryPolicy { boolean retry(int attempt); }
class PaymentProcessor {
    private final PaymentGateway gateway;
    private final RetryPolicy retryPolicy;      // injected behavior
    PaymentProcessor(PaymentGateway g, RetryPolicy r) {
        this.gateway = g; this.retryPolicy = r;
    }
}

The classification tells you where each pattern plugs in: Factory at the construction boundary, Adapter at the integration boundary, Strategy at the behavior-selection boundary. They compose without overlapping.

4. When to use / when NOT — the judgment layer

The classification is a diagnostic shortcut, not a mandate. Use it like this:

When NOT to classify at all: if you cannot state the recurring problem in one sentence, you are pattern-hunting, and forcing a category adds indirection with no payoff. Simple code that reads well always beats a pattern applied for its own sake.

5. Pitfalls — what interviewers probe

Key takeaways

🤖 Don't fully get this? Learn it with Claude

Stuck on Classification of Design Patterns? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Classification of Design Patterns** (OO & Low-Level Design) and want to truly understand it. Explain Classification of Design Patterns from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Classification of Design Patterns** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Classification of Design Patterns** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Classification of Design Patterns** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes