Observer Pattern

Learn the methods and implementation of the Observer Pattern.

For a software developer, it’s hard to hear about Observables and not think of the venerable Observer pattern. In it, we have an object called Producer that keeps an internal list of Listeners subscribed to it. Listeners are notified, by calling their update method, whenever the state of the Producer changes. In most explanations of the Observer pattern, this entity is called Subject, but to avoid confusion with RxJS’s own Subject type, we call it Producer.

It’s easy to implement a rudimentary version of the pattern in a few lines:

Get hands-on with 1400+ tech skills courses.