1700482876
public ProductEventType getEventType(){
1700482877
1700482878
return this.type;
1700482879
1700482880
}
1700482881
1700482882
//通知事件处理中心
1700482883
1700482884
private void notifyEventDispatch(){
1700482885
1700482886
super.addObserver(EventDispatch.getEventDispathc());
1700482887
1700482888
super.setChanged();
1700482889
1700482890
super.notifyObservers(source);
1700482891
1700482892
}
1700482893
1700482894
}
1700482895
1700482896
我们在产品事件类中增加了一个私有方法notfiyEventDispatch,该方法的作用是明确事件的观察者,并同时在初始化时通知观察者,它在有参构造中被调用。我们再来看事件的观察者,如代码清单36-5所示。
1700482897
1700482898
代码清单36-5 事件的观察者
1700482899
1700482900
public class EventDispatch implements Observer{
1700482901
1700482902
//单例模式
1700482903
1700482904
private final static EventDispatch dispatch=new EventDispatch();
1700482905
1700482906
//不允许生成新的实例
1700482907
1700482908
private EventDispatch(){
1700482909
1700482910
}
1700482911
1700482912
//获得单例对象
1700482913
1700482914
public static EventDispatch getEventDispathc(){
1700482915
1700482916
return dispatch;
1700482917
1700482918
}
1700482919
1700482920
//事件触发
1700482921
1700482922
public void update(Observable o,Object arg){
1700482923
1700482924
}
1700482925
[
上一页 ]
[ :1.700482876e+09 ]
[
下一页 ]