Problem: How to maintain consistency between multiple observers of an observable
object's state information?
Solution: Observer Pattern
Outline: Consider an Observable Supplier object with Number, Name, Status, City.
Two Observer Frames both display the information about this particular Supplier:
A user modifies two fields in the first Frame, and pushes SUBMIT
The goal is to have the other Frame(s) automatically refresh their own displays:
Observer Pattern: UML [61]
Supplier inherits from Java's Observable class
ObsFrame implements Java's Observer interface
Many ObsFrames observe the one Supplier
Each ObsFrame registers itself with the Supplier via addObserver(this)
addObserver() puts the Observer into the Vector of all Observers
If a ObsFrame does a SUBMIT, then it mutates the Supplier
Supplier calls notifyObservers()
notifyObservers() iterates through the Vector, and calls each Observers's update()
update() is the automatic update (callback) which allows the ObsFrame to refresh the display
Refresh can be performed by using the Supplier's accessor methods
SEE CASE STUDY