الأنماط السلوكية تتعامل مع كيفية تفاعل الكائنات والتواصل بينها — توزيع المسؤوليات وتدفق الاتصال بين الكائنات. وتتضمن 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)
