Observer pattern

The Observer pattern is a Gang of Four pattern. It is a pattern made famous by being included in the book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The pattern has two key players involved: a Subject and an Observer. A Subject is observed by an Observer. Typically, a Subject holds an internal list of Observers that should be notified when a change happens on the Subject. It is quite common that the Subject is a model and the Observers are some kind of UI component. In short, Subjects should be able to:

  • Hold a list of Observers
  • Add an Observer
  • Remove an Observer
  • Notify all Observers when a change happens

The Observer, on the other hand, ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.