Behavioral Design Patterns

All 23 classic Gang of Four patterns for object-oriented software design.

11 patterns
Behavioral

Chain of Responsibility

Passes a request along a line of handlers until one of them takes care of it.

Behavioral

Command

Wraps a request as a standalone object, so it can be queued, logged, or undone independently of its trigger.

Behavioral

Interpreter

Represents each grammar rule of a small language as a class, so a sentence becomes a tree that can evaluate itself.

Behavioral

Iterator

Provides one consistent way to walk through a collection without exposing how it's stored.

Behavioral

Mediator

Moves the tangled communication between a group of objects into one go-between object.

Behavioral

Memento

Captures an object's state in a snapshot that can restore it later without exposing its internals.

Behavioral

Observer

Lets any number of objects subscribe to and get notified about another object's changes.

Behavioral

State

Lets an object change its entire behavior at runtime by switching between interchangeable state objects.

Behavioral

Strategy

Packages interchangeable algorithms into their own classes so they can be swapped at runtime.

Behavioral

Template Method

Fixes the overall steps of an algorithm in a base class while letting subclasses fill in the details.

Behavioral

Visitor

Moves an operation out of the classes it works on and into its own class, so adding operations doesn't require changing those classes.