kaapo
Interface Observer

All Known Implementing Classes:
ActorGraphics, AssociationGraphics, AttributePanel, AttributeView, ConnectionGraphics, DataBaseGraphics, DataFlowGraphics, DataStoreGraphics, DCGraphics, DependencyGraphics, DiagramPanel, DiagramView, GeneralizationGraphics, GenericAttributePanel, KaapoGui, ProcessGraphics, ProjectView, SolidGraphics, TextGraphics, UseCaseGraphics

public interface Observer

This class represents an observer object. A class can implement the Observer interface when it wants to be informed of changes in an observable object's state.

This is basically the same as Java's Observer interface. All implementing classes have to write own update methods to react to changes in subject's state. The update method is supposed to be called from subject's notifyObservers method.

It may be good idea to use Enums as notifyObserver method's message parameter and then test message objects equality in update method.

Remember that the observers will remain be in the memory until they are removed form Observables observer list or the observable itself is trashed!

TODO: Parempi tapa tämän tekemiseen olisi niin, että addObserver-metodia kutsutaan aina observersin ulkopuolelta, samoin kuin vastaavaa removeObserver-metodia ennen viitteen kadottamista. Update-metodin tulisi voida hakea kaikki tarvittavat tiedot. Korjataan jos ehditään...

Author:
paltamaa
See Also:
Observable, Observer, Observer design pattern

Method Summary
 void removeObserver()
          This method should be called before disposing an observer.
 void update(Observable subject, Object message)
          This method is called whenever the observed object is changed.
 

Method Detail

update

void update(Observable subject,
            Object message)
This method is called whenever the observed object is changed. An application calls an Observable object's notifyObservers method to have all the object's observers notified of the change.

It's safe to modify the subject's observer list from update method. It won't affect the current notify round though, but the next.

Parameters:
subject - the subject that fires the update
message - the message delivered to observer

removeObserver

void removeObserver()
This method should be called before disposing an observer. The implementation should take care to save reference to observable so that it can remove itself from observables observer list whern asked.

The reason for this is that the observer will remain in memory as long as there is references to it in it's observables' observer list. Observer will also receive updates until it's removed from all lists.