源码分析
Java内置观察者模式使用了一个类 Observable,一个接口 Observer
分析类 Observable
private boolean changed = false;
private Vector<Observer> obs;
/** Construct an Observable with zero Observers. */
public Observable() {
obs = new Vector<>();
}
notifyObservers()和notifyObservers(Object)依赖于 changed的状态,判断changed状态来决定观察者是否update,
在更新完成后clearChanged();
/**
* If this object has changed, as indicated by the
* <code>hasChanged</code> method, then notify all of its observers
* and then call the <code>clearChanged</code> method to
* indicate that this object ha