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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.