1700483050
1700483051
public class EventDispatch implements Observer{
1700483052
1700483053
//单例模式
1700483054
1700483055
private final static EventDispatch dispatch=new EventDispatch();
1700483056
1700483057
//事件消费者
1700483058
1700483059
private Vector<EventCustomer>customer=new Vector<EventCustomer>();
1700483060
1700483061
//不允许生成新的实例
1700483062
1700483063
private EventDispatch(){
1700483064
1700483065
}
1700483066
1700483067
//获得单例对象
1700483068
1700483069
public static EventDispatch getEventDispathc(){
1700483070
1700483071
return dispatch;
1700483072
1700483073
}
1700483074
1700483075
//事件触发
1700483076
1700483077
public void update(Observable o,Object arg){
1700483078
1700483079
//事件的源头
1700483080
1700483081
Product product=(Product)arg;
1700483082
1700483083
//事件
1700483084
1700483085
ProductEvent event=(ProductEvent)o;
1700483086
1700483087
//处理者处理,这里是中介者模式的核心,可以是很复杂的业务逻辑
1700483088
1700483089
for(EventCustomer e:customer){
1700483090
1700483091
//处理能力是否匹配
1700483092
1700483093
for(EventCustomType t:e.getCustomType()){
1700483094
1700483095
if(t.getValue()==event.getEventType().getValue()){
1700483096
1700483097
e.exec(event);
1700483098
1700483099
}
[
上一页 ]
[ :1.70048305e+09 ]
[
下一页 ]