Skip to content

Observer design pattern

Devrath edited this page Dec 2, 2023 · 7 revisions

1516900483662

When to use this pattern

  • Assume there is a data source that we can call an observable and there are many clients who are observers listening for the change in the data of the observable. When there is a change in observable` all the observers are notified.
  • Now we need The data source to talk to all the observers without being tightly coupled.
  • We can use an interface called observer and make data source to talk to the interface.
  • This preserves the open-closed principle meaning a functionality is open for extension and closed for modification.
  • There is a push and pull style approach. We are using the pull style approach in our case since it the best approach.