打字猴:1.70046372e+09
1700463720
1700463721 public abstract void execute();
1700463722
1700463723 }
1700463724
1700463725 在Command父类中声明了一个接收者,通过构造函数约定每个具体命令都必须指定接收者,当然根据开发场景要求也可以有多个接收者,那就需要用集合类型。我们来看具体命令,如代码清单15-23所示。
1700463726
1700463727 代码清单15-23 具体的命令
1700463728
1700463729 public class ConcreteCommand1 extends Command{
1700463730
1700463731 //声明自己的默认接收者
1700463732
1700463733 public ConcreteCommand1(){
1700463734
1700463735 super(new ConcreteReciver1());
1700463736
1700463737 }
1700463738
1700463739 //设置新的接收者
1700463740
1700463741 public ConcreteCommand1(Receiver_receiver){
1700463742
1700463743 super(_receiver);
1700463744
1700463745 }
1700463746
1700463747 //每个具体的命令都必须实现一个命令
1700463748
1700463749 public void execute(){
1700463750
1700463751 //业务处理
1700463752
1700463753 super.receiver.doSomething();
1700463754
1700463755 }
1700463756
1700463757 }
1700463758
1700463759 public class ConcreteCommand2 extends Command{
1700463760
1700463761 //声明自己的默认接收者
1700463762
1700463763 public ConcreteCommand2(){
1700463764
1700463765 super(new ConcreteReciver2());
1700463766
1700463767 }
1700463768
1700463769 //设置新的接收者
[ 上一页 ]  [ :1.70046372e+09 ]  [ 下一页 ]