Field Guide · concept

Behavioral patterns are the Gang of Four family that handles the question once objects exist and are connected: how do they talk to each other and divide up the work? They are about communication and responsibility at runtime.12

subject observer observer observer FmDemod AmDemod swappable strategy
A subject notifies many observers at once, while a context delegates to a swappable strategy or state object.

What they are for

The hard part of a running program is rarely a single object — it is the interactions. When a call is decoded, the UI, the logger, and the recorder all need to know; when the user picks a mode, the right algorithm must run; when a follower moves from idle to active, its whole behaviour changes. Handling each with ad-hoc code scatters logic and tightens coupling. Behavioral patterns give these interactions a clean, named shape that keeps the parties from depending too directly on each other.1

The main members

  • Observer — a one-to-many dependency where a subject notifies all its observers when it changes, without knowing who is listening; the basis of publish/subscribe and UI events.
  • Strategy — a family of interchangeable algorithms behind a common interface, swappable at runtime (pick FM, AM, or SSB demodulation without branching logic).
  • State — each state is its own object owning its behaviour and transitions, so the object appears to change its class; the object-oriented expression of a state machine.
  • Command — wraps a request as an object so it can be queued, logged, or undone.
  • Iterator — exposes the elements of a collection one at a time without revealing its structure.
  • Template Method — a base class fixes the skeleton of an algorithm and lets subclasses fill in steps.

A common thread

Observer, Strategy, and State all let you add reactions, algorithms, or states by adding classes rather than editing existing code — the open/closed principle from SOLID in action. They rely on programming to an interface, just like the sibling creational and structural families catalogued under design patterns.

Sources

  1. Behavioral pattern — Wikipedia, for the definition, the focus on communication and control flow, and members such as Observer, Strategy, and State.  2

  2. Design Patterns — Wikipedia, on the 1994 Gang of Four book that catalogued these patterns alongside the creational and structural families. 

See also