Skip to content

Behavioral patterns

Patterns about how objects share responsibilities and talk to each other.

10 guides126 min in totalDesign patterns

The guides, in order

Read them top to bottom: each one builds on the ones before. The ones you've read carry a check.

  1. Chain of Responsibility: Pass a Request Along Until One Handles ItLearn Chain of Responsibility by routing returned parcels through a chain of disposition handlers, with TypeScript, Python and PHP code.14 min readStart here
  2. Command Pattern: Turn Requests into Objects You Can Queue and UndoLearn the Command pattern by building an offline-tolerant stock movement queue with logging, retries and undo for a chain of bike shops.13 min read
  3. Iterator Pattern: Walk Any Collection Without Knowing Its ShapeLearn the Iterator pattern with a bike-share example: traverse ring buffers and paged archives uniformly, using generators for lazy sequences.14 min read
  4. Mediator: Route Component Chatter Through One CoordinatorLearn the Mediator pattern by refactoring a coffee roaster's firmware so the probe, burner, door and fan stop calling each other directly.12 min read
  5. Memento Pattern: Save and Restore State Without Exposing ItLearn the Memento pattern through a seating planner that tries placements, checkpoints its state and rolls back cleanly, with TypeScript, Python and PHP code.13 min read
  6. Observer Pattern: Notify Subscribers Without Coupling to ThemLearn the Observer pattern through a bike-share dock example, including subscribe and unsubscribe, event payloads and listener memory leaks.13 min read
  7. State Pattern: Explicit State Machines Without the Switch StatementsLearn the State pattern by refactoring an EV charger's switch-heavy firmware into state objects that own their behaviour and transitions.13 min read
  8. Strategy: swap the rule without touching who uses itThe Strategy pattern explained with a helpdesk that assigns tickets: one interface per decision, one class per rule, chosen by configuration.9 min read
  9. Template Method: A Fixed Algorithm With Steps Subclasses Fill InLearn the Template Method pattern by building a bike-share ride-closing flow where the base class fixes the steps and subclasses supply the details.13 min read
  10. Visitor Pattern: Add Operations Without Editing Your ClassesLearn the Visitor pattern: how double dispatch lets you add new operations over a stable object structure without modifying its classes.12 min read

About this group

What you'll find
Strategy, Observer, Command, State, Template Method, Chain of Responsibility, Iterator, Mediator, Memento and Visitor.
It's for you if…
you're asked how to swap a rule, react to events or undo operations without filling the code with conditionals.
How each guide works
Each guide explains the problem the pattern solves, the solution and an analogy, with a structure diagram and its participants. Then come when to apply it, how to implement it step by step, pros and cons, how it relates to other patterns and code in TypeScript, Python and PHP.