|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkaapo.Observable
public abstract class Observable
This class represents an observable object, or "data" in the model-view paradigm. It can be subclassed to represent an object that the application wants to have observed. Subclassing classes must take care to call setChanged and notifyObserver method whenever their state changes.
This is basically the same as Java's Observable class, except that the observer list is marked as transient, meaning that it wont be serialized by object serialization. That way a project can be saved without any references to application GUI or some other classes.
The notifyObservers methods won't do anything unless the subject's state is set to changed by calling it's setChanged method.
It may be good idea to use Enums as notifyObserver method's message parameter and then test message objects equality in update method.
Observer
,
Observable
,
Observer design patternConstructor Summary | |
---|---|
Observable()
Creates new Observable object with no observers. |
Method Summary | |
---|---|
void |
addObserver(Observer observer)
Adds new observer to this subject. |
void |
notifyObservers()
Notifies all observers by calling their update method with null message. |
void |
notifyObservers(Object message)
Notifies all observers by calling their update method with given message. |
void |
removeAllObservers()
Removes all observers from this subject. |
void |
removeObserver(Observer observer)
Removes an observer from this subject. |
void |
setChanged()
Sets this observers state to changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Observable()
Method Detail |
---|
public void addObserver(Observer observer)
observer
- the observer to addpublic void removeObserver(Observer observer)
observer
- the observer to removepublic void removeAllObservers()
public void setChanged()
public void notifyObservers()
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.
public void notifyObservers(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.
message
- Message to send
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |