打字猴:1.700482304e+09
1700482304 }
1700482305
1700482306 }
1700482307
1700482308 一个简单的工厂,根据策略管理类的枚举项创建一个策略对象,简单而实用,策略模式的缺陷也弥补成功。那这么复杂的系统怎么让高层模块访问?(你看不出复杂?那是因为我们写的都是快乐路径,太多情况都没有考虑,在实际项目中仅就并发处理和事务管理这两部分就够你头疼了。)既然系统很复杂,是不是需要封装一下。我们请出门面模式进行封装,如代码清单35-9所示。
1700482309
1700482310 代码清单35-9 扣款模块封装
1700482311
1700482312 public class DeductionFacade{
1700482313
1700482314 //对外公布的扣款信息
1700482315
1700482316 public static Card deduct(Card card,Trade trade){
1700482317
1700482318 //获得消费策略
1700482319
1700482320 StrategyMan reg=getDeductionType(trade);
1700482321
1700482322 //初始化一个消费策略对象
1700482323
1700482324 IDeduction deduction=StrategyFactory.getDeduction(reg);
1700482325
1700482326 //产生一个策略上下文
1700482327
1700482328 DeductionContext context=new DeductionContext(deduction);
1700482329
1700482330 //进行扣款处理
1700482331
1700482332 context.exec(card,trade);
1700482333
1700482334 //返回扣款处理完毕后的数据
1700482335
1700482336 return card;
1700482337
1700482338 }
1700482339
1700482340 //获得对应的商户消费策略
1700482341
1700482342 private static StrategyMan getDeductionType(Trade trade){
1700482343
1700482344 //模拟操作
1700482345
1700482346 if(trade.getTradeNo().contains(“abc”)){
1700482347
1700482348 return StrategyMan.FreeDeduction;
1700482349
1700482350 }else{
1700482351
1700482352 return StrategyMan.SteadyDeduction;
1700482353
[ 上一页 ]  [ :1.700482304e+09 ]  [ 下一页 ]