يعرّف نمط Observer تبعية من واحد إلى متعدد حيث يتم إخطار عدة كائنات (المراقبون) تلقائياً عندما يتغير حالة كائن آخر (الموضوع). يمكّن الاتصال المفكوك والمدفوع بالأحداث — يستخدم على نطاق واسع في واجهات المستخدم وأنظمة الأحداث والبرمجة التفاعلية.
ما يفعله نمط Observer
OBSERVER → a SUBJECT maintains a list of OBSERVERS and NOTIFIES them on state changes:
→ observers SUBSCRIBE to the subject
→ when the subject changes → it notifies ALL subscribed observers automatically
→ observers react to the notification (update themselves)
→ one-to-many: one subject, many observers; DECOUPLED (subject doesn't know observer details)
