打字猴:1.700483176e+09
1700483176
1700483177 //克隆事件
1700483178
1700483179 CLONE(4);
1700483180
1700483181 private int value=0;
1700483182
1700483183 private EventCustomType(int_value){
1700483184
1700483185 this.value=_value;
1700483186
1700483187 }
1700483188
1700483189 public int getValue(){
1700483190
1700483191 return value;
1700483192
1700483193 }
1700483194
1700483195 }
1700483196
1700483197 我们在系统中定义了3个事件处理者,分别是乞丐、平民和贵族。乞丐只能获得别人遗弃的物品,平民消费自己生产的东西,自给自足,而贵族则可以获得精修的产品或者是绿色产品(也就是我们这里的克隆产品,不用自己劳动获得的产品)。我们先看乞丐的源代码,如代码清单36-10所示。
1700483198
1700483199 代码清单36-10 乞丐
1700483200
1700483201 public class Beggar extends EventCustomer{
1700483202
1700483203 //只能处理被人遗弃的东西
1700483204
1700483205 public Beggar(){
1700483206
1700483207 super(EventCustomType.DEL);
1700483208
1700483209 }
1700483210
1700483211 @Override
1700483212
1700483213 public void exec(ProductEvent event){
1700483214
1700483215 //事件的源头
1700483216
1700483217 Product p=event.getSource();
1700483218
1700483219 //事件类型
1700483220
1700483221 ProductEventType type=event.getEventType();
1700483222
1700483223 System.out.println(“乞丐处理事件:”+p.getName()+“销毁,事件类型=”+type);
1700483224
1700483225 }
[ 上一页 ]  [ :1.700483176e+09 ]  [ 下一页 ]