命令模式

命令模式

 public interface Command {
     void  execute();
 }
 
 public class CommandA  implements Command{
     public void execute() {
         System.out.println("a执行了");
    }
 }
 
 public class CommandB  implements Command{
     public void execute() {
         System.out.println("生成html");
         System.out.println("执行业务流程");
         System.out.println("生成文书");
         System.out.println("上传文档");
    }
 }
 
 
 public class Invoker {
     private Command command;
 
     public Invoker(Command command) {
         this.command = command;
    }
 
     public void execute(){
         this.command.execute();
    }
 }
 
 public class Main {
     public static void main(String[] args) {
         CommandA commandA = new CommandA();
         CommandB commandB = new CommandB();
 
         Invoker invoker = new Invoker(commandB);
         invoker.execute();
 
         Invoker invoker2 = new Invoker(commandA);
         invoker2.execute();
    }
 }
 

 

posted @ 2021-05-13 23:26  三号小玩家  阅读(51)  评论(0编辑  收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840