ビヘイビアルパターンは、オブジェクト間の相互作用と通信——責任の割り当てとオブジェクト間の通信フロー——を扱います。Observer、Strategy、Command、Iterator、State、Template Method などが含まれます。
ビヘイビアルパターンが対処すること
BEHAVIORAL patterns concern how objects INTERACT, communicate, and distribute
responsibilities:
→ how objects collaborate and assign responsibilities to achieve behavior
→ manage algorithms, communication, and control flow between objects
→ about BEHAVIOR and interaction, not creation or structure
主要なビヘイビアルパターン
OBSERVER → notify many objects of state changes (covered separately) — very common
STRATEGY → interchangeable algorithms, swappable at runtime (covered separately) — common
COMMAND → encapsulate a request as an object (queue, log, undo operations)
ITERATOR → traverse a collection without exposing its internal structure
STATE → change behavior based on internal state (an object behaving like different "states")
TEMPLATE METHOD → define an algorithm's skeleton, let subclasses fill in steps
CHAIN OF RESPONSIBILITY → pass a request along a chain of handlers until one handles it
MEDIATOR → centralize complex communication between objects (reduce direct coupling)
