Pola Observer mendefinisikan ketergantungan satu-ke-banyak di mana beberapa objek (observers) diberi tahu secara otomatis ketika objek lain (subject) mengubah state. Pola ini memungkinkan komunikasi yang decoupled dan event-driven — banyak digunakan dalam UI, sistem event, dan reactive programming.
Apa yang dilakukan pola 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)
