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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s