- Determine what object’s data that other classes need updates on (this object will be Observable).
- Determine the classes that will receive the updates of the data change (these objects will be the Observers).
- Have the Observable class extend java.util.Observable
- 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();
- Have the Observer classes implement java.util.Observer
- Create a method called update that does something once you get notified.
Advertisement
You got the the observer pattern, good job.