Vzorec Observer definira odvisnost ena-do-več, kjer se več objektov (opazovalci) samodejno obvestil, ko se stanje drugega objekta (subjekta) spremeni. Omogoča sklopljeno, v dogodkih poganjano komunikacijo — pogosto se uporablja v uporabniškem vmesniku, sistemih dogodkov in reaktivnem programiranju.
Kaj počne vzorec 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)
