|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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...
Observable
,
Observer
,
Observer design patternMethod 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 |
---|
void update(Observable subject, Object message)
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.
subject
- the subject that fires the updatemessage
- the message delivered to observervoid removeObserver()
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |