package org.ustc.command;
public class Bbqer {
public String name;
public void BakeChickenWing(){
System.out.println("烧烤鸡翅");
}
public void BakeMutton(){
System.out.println("烧烤羊肉串");
}
}
package org.ustc.command;
public abstract class Command {
protected Bbqer bbqer;
public Command(Bbqer bbqer){
this.bbqer = bbqer;
}
abstract void executeCommand();
}
package org.ustc.command;
public class ExcuteChickenWing extends Command {
public ExcuteChickenWing(Bbqer bbqer) {
super(bbqer);
// TODO Auto-generated constructor stub
}
@Override
void executeCommand() {
// TODO Auto-generated method stub
bbqer.BakeChickenWing();
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "烤鸡翅";
}
}
package org.ustc.command;
public class ExecuteMutton extends Command {
public ExecuteMutton(Bbqer bbqer) {
super(bbqer);
// TODO Auto-generated constructor stub
}
@Override
void executeCommand() {
// TODO Auto-generated method stub
bbqer.BakeMutton();
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "烤羊肉串";
}
}
package org.ustc.command;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Waiter {
private List<Command> orderList;
public Waiter() {
this.orderList = new ArrayList<Command>();
}
public void addOrder(Command command){
orderList.add(command);
}
public void removeOrder(Command command){
if(orderList.contains(command)){
orderList.remove(command);
Date time = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String currentTime = df.format(time);
System.out.println("取消"+command+"时间:"+currentTime);
}
}
public void executeCommand(){
for(Command command:orderList){
command.executeCommand();
}
}
}
package org.ustc.command;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Bbqer boy = new Bbqer();
Waiter waiter = new Waiter();
Command kyrc1 = new ExecuteMutton(boy);
Command kyrc2 = new ExecuteMutton(boy);
Command kjc = new ExcuteChickenWing(boy);
waiter.addOrder(kjc);
waiter.addOrder(kyrc1);
waiter.addOrder(kyrc2);
waiter.removeOrder(kyrc2);
waiter.executeCommand();
}
}
package org.ustc.command;public class Bbqer { public String name; public void BakeChickenWing(){ System.out.println("烧烤鸡翅"); } public void BakeMutton(){ System.out.println("烧烤羊肉串"); }}pac