Step-by-Step: Using the Observer Pattern

1. Create two interfaces: Observable and Observer.

2. The Observable interface should contain the following methods:

  • registerObserver() – registers Observers to receive updates
  • removeObserver() – removes Observers from receive updates
  • notifyObservers() – notify Observers of an updates using Push/Pull
  • setChanged() – Optional, but let’s you control what updates should be sent

3. The Observer interface should contain the following method:

  • update() – retrieves updated data from the Observable for Observers

Leave a comment