WEB开发网
开发学院软件开发Java hand first 设计模式 - 命令模式 阅读

hand first 设计模式 - 命令模式

 2009-09-17 00:00:00 来源:WEB开发网   
核心提示: 关闭看电视组合命令 Java代码publicclassLookTvOffCommandimplementsCommand{//命令组合privateCommand[]commands;publicLookTvOffCommand(Command[]commands){this.commands=

关闭看电视组合命令

Java代码   

public class LookTvOffCommand implements Command { 
     //命令组合 
 private Command[] commands; 
 
 public LookTvOffCommand(Command[] commands) { 
 this.commands = commands; 
 } 
 
 @Override 
     //执行命令组合 
 public void execute() { 
 // TODO Auto-generated method stub 
 for (Command command : commands) { 
  command.execute(); 
 } 
 
 } 
 
 @Override 
     //撤消命令组合 
 public void undo() { 
 // TODO Auto-generated method stub 
 for (Command command : commands) { 
  command.undo(); 
 } 
 
 } 
 
}

开启看电视组合命令

Java代码   

public class LookTvOnCommand implements Command { 
 
 private Command[] commands; 
 
 public LookTvOnCommand(Command[] commands) { 
 this.commands = commands; 
 } 
 
 @Override 
 public void execute() { 
 // TODO Auto-generated method stub 
 for(Command command:commands){ 
  command.execute(); 
 } 
 
 } 
 
 @Override 
 public void undo() { 
 // TODO Auto-generated method stub 
 for(Command command:commands){ 
  command.undo(); 
 } 
 
 } 
 
}

上一页  1 2 3 4 5  下一页

Tags:hand first 设计模式

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接