So, I’ve been looking at Design Patterns lately, and I’ve decided to document a couple, starting with the Observer Pattern.
The basic gist of it is that you have an “observable” class/interface (in this case Subject implemented as MyTopic) which has, amongst others, the methods register(Observer obj) and notifyObservers().
You then pass in concrete instances of the interface Observer (in this case MyTopicSubscriber) via the subject.register() method, and then – any time the Subject is altered or otherwise interacted with, it can then call notifyObservers() and then – via calls to each of the Observer object’s update() method, everyone in that list of Observers can be informed.
That’s about it, really. Seems simple!