Let’s Build a Thing! (Part Two)

The Observer Pattern

Test #1 — Observers are registered

Test #2 — Observers are notified

Enter Proxy

  • The Controller class is now abstract. To use its functionality, you derive your own implementation of Controller. The management of Observability is handled by the superclass so we no longer have to worry about it!
  • Derived Controller instances now need to provide an implementation of a function called data. This function returns a plain-old-javascript object which defines the initial state of the Controller. Each Controller derivative is going to use this state variable for the day-to-day gubbins of Controller management/lifecycle etc.
  • The constructor of the Controller class initialises a new, protected property called state. This Proxy variable provides an implementation of the set trap which simply iterates its Observables and calls update.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chris Shepherd

Chris Shepherd


Thoughtworks.com dev, barbershopper, homebrewer and human (not necessarily in that order).