Low-Level Design9h estimated

Behavioral Design Patterns

Difficulty
Importance

The problem

Objects need to communicate, coordinate, and change behavior at runtime in ways that hardcoded if/else chains handle poorly — behavioral patterns are named strategies for organizing communication and responsibility between objects that keep that coordination flexible instead of tangled.

Why now

Higher-order functions already showed that passing behavior itself as a value — not just data — unlocks flexible, swappable logic; behavioral patterns are that exact idea implemented with objects and polymorphism instead of first-class functions, for languages and situations where an object, not a bare function, is the natural unit of swappable behavior.

Mental model

Strategy makes an algorithm swappable by passing in a behavior-object instead of hardcoding logic — the object-oriented twin of passing a callback to a higher-order function. Observer lets objects subscribe to another object's changes without tight coupling. State lets an object change its entire behavior when its internal state changes, avoiding a sprawling switch statement. Each pattern replaces a rigid conditional with polymorphism doing the deciding instead.

Requires

Unlocks

Used in

Projects

  • Implement a Strategy pattern for a payment system supporting CreditCard, PayPal, and Crypto payment strategies, swappable without modifying the checkout class
  • Implement an Observer pattern where multiple UI components subscribe to and react to a single shared data source's changes

Examples

  • A PricingStrategy interface with RegularPricing, SalePricing, and MemberPricing implementations lets checkout logic stay identical while the pricing algorithm varies
  • A TrafficLight object using the State pattern delegates its next() behavior entirely to its current RedState/YellowState/GreenState object, avoiding a sprawling if/else chain

Resources

Mastery checklist