Observer पैटर्न एक एक-से-अनेक निर्भरता परिभाषित करता है जहाँ कई ऑब्जेक्ट्स (observers) को स्वचालित रूप से सूचित किया जाता है जब कोई दूसरा ऑब्जेक्ट (subject) अपनी स्थिति बदलता है। यह decoupled, इवेंट-संचालित संवाद को सक्षम करता है — UIs, इवेंट सिस्टम, और reactive प्रोग्रामिंग में व्यापक रूप से उपयोग किया जाता है।
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)
