Participants
- Subject (Publisher) — maintains the observer list; provides
subscribe / unsubscribe / notify methods - Observer (Subscriber) — implements an
update() method called by the subject
Where it appears
- DOM events in the browser (
addEventListener) - Event systems in frameworks (EventEmitter in Node.js)
- Reactive Programming (RxJS Observable)
- In-application message bus
Observer vs Pub/Sub
In Observer, the subject knows its observers directly. In Pub/Sub there is a broker between them: publisher and subscriber are unaware of each other.