Zleef’s Blog

I wish i was swimming here –but instead, i’ll happily work on my computer science homework…

How to implement the Observer Pattern:

  1. Determine what object’s data that other classes need updates on (this object will be Observable).
  2. Determine the classes that will receive the updates of the data change (these objects will be the Observers).
  3. Have the Observable class extend java.util.Observable
  4. Within the method that updates the data you wanted others to get notified (i.e. where ever it is that the data gets modified), place a call to setChanged(); and notifyObservers(); 
  5. Have the Observer classes implement java.util.Observer
  6. Create a method called update that does something once you get notified.
Advertisement

1 Comment»

  danielmundra wrote @

You got the the observer pattern, good job.


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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.