package command_pattern;
public interface Receive {
boolean do_thing();
}
package command_pattern;
public class Program_Receive implements Receive {
@Override
public boolean do_thing() {
// TODO Auto-generated method stub
System.out.println("我可以负责编程");
return false;
}
}
package command_pattern;
public class Clean_Receive implements Receive{
@Override
public boolean do_thing() {
// TODO Auto-generated method stub
System.out.println("我可以负责打扫卫生");
return false;
}
}
package command_pattern;
public interface Command {
//Receive person;
void command_do();
}
package command_pattern;
public class Program_Command implements Command {
@Override
public void command_do() {
// TODO Auto-generated method stub
Receive receive = new Program_Receive();
receive.do_thing();
}
}
package command_pattern;
public class Clean_Command implements Command {
@Override
public void command_do() {
// TODO Auto-generated method stub
Receive receive = new Clean_Receive();
receive.do_thing();
}
}
package command_pattern;
public class Invlove {
Command command ;
Invlove(Command command){
this.command = command;
}
boolean setcommand(Command command){
this.command = command;
return false;
}
boolean Execute(){
command.command_do();
return true;
}
}
package command_pattern;
public class App {
public static void main(String[] args) {
Program_Command s = new Program_Command();
Invlove good = new Invlove(s);
good.Execute();
good.setcommand(new Clean_Command());
good.Execute();
}
}