public abstract class Observable
extends java.lang.Object
implements java.lang.Cloneable
Constructor and Description |
---|
Observable() |
Modifier and Type | Method and Description |
---|---|
void |
addObserver(Observer observer)
adds an observer which will be notified when ever this observable
'changes'.
|
java.lang.Object |
clone()
returns a shallow copy of this observable which has no observers.
|
void |
fireChangeEvent()
notifies immediately all observers that this observable has 'changed'.
|
void |
removeObserver(Observer observer)
removes the observer from this observable.
|
public void addObserver(Observer observer)
The observer may be notified even if no real change has occurred so the observer should be prepared to handle that case and not depend on that a notification only happens if an actual change has occurred.
A case in point is that when an Observer
is added the
observer gets the very first notification when right after it has been
added, this eliminates the need for observer to initialize itself by some
other means, instead it can always rely on obtaining its 'value' from the
observable inside the Observer.valueChanged(Observable)
method.
observer
- the observer to be addedpublic void removeObserver(Observer observer)
observer
- the observer to be removed.public void fireChangeEvent()
public java.lang.Object clone()
clone
in class java.lang.Object