Design Pattern - Observer (Publish-subscribe model|Pub Sub)
About
An observer makes a observation by creating an event and passing it to a callback method of the subscriber.
The observer is also called a message broker because it dispatches the event (ie message) to the subscriber (pubsub).
The observer is used a fundamental pattern of Reactive programming
Usage
- chat - when a message is posted, all peoples in the chatroom are noticed
- data replication - when a insert happens in a database, a insert happens in a replica
- Recalculation of derived measure.
- Excel, if you change the value of a cell, the formulas using this cell are immediately recalculated.
- User interface: If you delete a notification, the notification count should decrease, …
Library
- Javascript: daniellmb/MinPubSub
- Redis has a native pubsub mechanism