Design Pattern - Observer (Publish-subscribe model|Pub Sub)


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


  • 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, …


Powered by ComboStrap