打字猴:1.70048285e+09
1700482850 }
1700482851
1700482852 //事件源头以及事件类型
1700482853
1700482854 public ProductEvent(Product p,ProductEventType_type){
1700482855
1700482856 this.source=p;
1700482857
1700482858 this.type=_type;
1700482859
1700482860 //事件触发
1700482861
1700482862 notifyEventDispatch();
1700482863
1700482864 }
1700482865
1700482866 //获得事件的始作俑者
1700482867
1700482868 public Product getSource(){
1700482869
1700482870 return source;
1700482871
1700482872 }
1700482873
1700482874 //获得事件的类型
1700482875
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
[ 上一页 ]  [ :1.70048285e+09 ]  [ 下一页 ]