Back to Low-Level Design
🔄
Phase 4

Behavioral Design Patterns

Patterns for communication between objects. These patterns define how objects interact, distribute responsibility, and encapsulate behavior. This is where most LLD interview solutions live.

1

Strategy Pattern: Swapping Algorithms at Runtime

Replace sprawling if/else chains with interchangeable algorithm objects — the pattern behind pricing engines, sort comparators, and payment routing.

lldbehavioralstrategy
2

Template Method Pattern: Fixing the Skeleton, Letting Subclasses Fill In Steps

Define the invariant shape of an algorithm once in a base class, and let subclasses override only the steps that actually vary — the Hollywood Principle in practice.

lldbehavioralstrategy
3

Observer Pattern: One-to-Many Notification

Let a subject notify every interested dependent automatically on state change — the foundation of event-driven programming, and the pattern behind every listener API you've used.

lldbehavioralobserver
4

Publish-Subscribe Pattern: Decoupling Producers from Consumers

Generalize Observer with an event broker in the middle — publishers and subscribers never know about each other, only about topics.

lldbehavioralobserver
5

Command Pattern: Encapsulating Requests as Objects

Turn an action into an object you can queue, log, undo, and replay — the pattern behind text editor undo stacks, job queues, and transactional workflows.

lldbehavioralcommand
6

Chain of Responsibility: Routing a Request Through Handlers

Pass a request along a chain of handlers until one processes it — the pattern behind servlet filters, middleware pipelines, and exception handling chains.

lldbehavioralcommand
7

State Pattern: Replacing Conditionals with State Objects

How to let an object change its behavior when its internal state changes, by replacing sprawling status conditionals with a family of state objects.

lldbehavioralstate
8

Mediator Pattern: Centralizing Peer-to-Peer Communication

How to untangle a mesh of objects that all talk directly to each other by routing their communication through a single mediator.

lldbehavioralmediator
9

Iterator Pattern: Traversing Collections Without Exposing Structure

How to walk through any collection's elements sequentially without leaking how that collection stores them internally, and why fail-fast and fail-safe iterators behave so differently.

lldbehavioraliterator
10

Memento Pattern: Capturing and Restoring Object State

How to implement undo and snapshot functionality by capturing an object's internal state externally, without breaking its encapsulation.

lldbehavioralmemento
11

Visitor Pattern: Adding Operations Without Changing Classes

How to add new operations over a family of classes without modifying them, using double dispatch — and why it's the pattern behind every AST-walking compiler.

lldbehavioralvisitor