1700483226
1700483227
}
1700483228
1700483229
乞丐在无参构造中定义了自己只能处理删除的事件,然后在exec方法中定义了事件的处理逻辑,每个处理者都是只要完成这两个方法即可,我们再来看平民级别的事件处理者,如代码清单36-11所示。
1700483230
1700483231
代码清单36-11 平民
1700483232
1700483233
public class Commoner extends EventCustomer{
1700483234
1700483235
//定义平民能够处理的事件的级别
1700483236
1700483237
public Commoner(){
1700483238
1700483239
super(EventCustomType.NEW);
1700483240
1700483241
}
1700483242
1700483243
@Override
1700483244
1700483245
public void exec(ProductEvent event){
1700483246
1700483247
//事件的源头
1700483248
1700483249
Product p=event.getSource();
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
}
[
上一页 ]
[ :1.700483226e+09 ]
[
下一页 ]