Observer pattern ਇਕ one-to-many dependency ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ ਜਿੱਥੇ ਕਈ ਵਸਤੂਆਂ (observers) ਸਵੈ-ਚਾਲਿਤ ਰੂਪ ਵਿੱਚ ਸੂਚਿਤ ਹੁੰਦੀਆਂ ਹਨ ਜਦੋਂ ਕੋਈ ਹੋਰ ਵਸਤੂ (subject) ਆਪਣੀ ਸਥਿਤੀ ਬਦਲਦੀ ਹੈ। ਇਹ decoupled, event-driven ਸੰਚਾਰ ਨੂੰ ਸਮਰਥ ਬਣਾਉਂਦਾ ਹੈ — ਜੋ UIs, event systems, ਅਤੇ reactive programming ਵਿੱਚ ਵਿਆਪਕ ਤੌਰ ਤੇ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।
Observer pattern ਕੀ ਕਰਦਾ ਹੈ
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)
