Intro

Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects — they describe not just patterns of objects and classes, but also the patterns of communication between them. They shift focus from flow control to collaboration, letting you compose behaviors without tightly coupling senders to receivers, algorithms to clients, or event producers to consumers. Reach for them when you need to orchestrate complex workflows, decouple notifications, make algorithms swappable at runtime, or traverse complex structures: Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor, Interpreter.

Patterns at a Glance

What unites the behavioral patterns is how responsibility and communication are distributed between objects. This is a catalog of intents, not a ranking — most compose freely.

PatternIntentReach for it when
Chain of ResponsibilityPass a request along a chain of handlers, each choosing to handle it or forward itSeveral objects might handle a request and the handler isn’t known in advance (middleware, escalation)
CommandEncapsulate a request as an object bundling action, parameters, and receiverYou need to queue, log, undo/redo, or replay operations
InterpreterDefine a grammar and an interpreter that evaluates sentences of a languageYou have a simple, stable language to evaluate (rules, expressions, DSLs)
IteratorProvide sequential access to a collection’s elements without exposing its structureClients must traverse a collection without depending on its internal representation
MediatorCentralize how a set of components interact, replacing a many-to-many web with one-to-many routingObjects communicate in complex ways and direct references have become tangled
MementoCapture and externalize an object’s state so it can be restored later, without breaking encapsulationYou need snapshots for undo, checkpoints, or rollback
ObserverDefine a one-to-many dependency so a subject’s change notifies all subscribersState changes in one object must fan out to many decoupled listeners (events)
StateExtract state-specific behavior into classes; the context delegates to its current stateBehavior changes with an internal mode and you want to avoid sprawling conditionals
StrategyDefine a family of interchangeable algorithms behind a common interfaceYou want to swap an algorithm at runtime, chosen by the client
Template MethodDefine an algorithm’s skeleton in a base class, letting subclasses override specific stepsMultiple variants share a fixed overall structure but differ in individual steps
VisitorAdd new operations to an object hierarchy without modifying its classes, via double dispatchYou add operations often but change the class hierarchy rarely

11 items under this folder.