打字猴:1.70048325e+09
1700483250
1700483251 //事件类型
1700483252
1700483253 ProductEventType type=event.getEventType();
1700483254
1700483255 System.out.println(“平民处理事件:”+p.getName()+“诞生记,事件类型=”+type);
1700483256
1700483257 }
1700483258
1700483259 }
1700483260
1700483261 平民只处理新建立的事件,其他事件不做处理,我们再来看贵族级别的事件处理者,如代码清单36-12所示。
1700483262
1700483263 代码清单36-12 贵族
1700483264
1700483265 public class Nobleman extends EventCustomer{
1700483266
1700483267 //定义贵族能够处理的事件的级别
1700483268
1700483269 public Nobleman(){
1700483270
1700483271 super(EventCustomType.EDIT);
1700483272
1700483273 super.addCustomType(EventCustomType.CLONE);
1700483274
1700483275 }
1700483276
1700483277 @Override
1700483278
1700483279 public void exec(ProductEvent event){
1700483280
1700483281 //事件的源头
1700483282
1700483283 Product p=event.getSource();
1700483284
1700483285 //事件类型
1700483286
1700483287 ProductEventType type=event.getEventType();
1700483288
1700483289 if(type.getValue()==EventCustomType.CLONE.getValue()){
1700483290
1700483291 System.out.println(“贵族处理事件:”+p.getName()+“克隆,事件类型=”+type);
1700483292
1700483293 }else{
1700483294
1700483295 System.out.println(“贵族处理事件:”+p.getName()+“修改,事件类型=”+type);
1700483296
1700483297 }
1700483298
1700483299 }
[ 上一页 ]  [ :1.70048325e+09 ]  [ 下一页 ]