interface Command{
void execute()throws Exception;
boolean isForOrder(String order);
}
class CommandA implements Command
{
public boolean isForOrder(String order)
{
return order.equals("1");
}
public void execute()throws Exception
{
// deal with order 1
}
}
class CommandB implements Command
{
public void execute()throws Exception
{
// deal with order 2
}
public boolean isForOrder(String order)
{
return order.equals("2");
}
}
方法有很多种,这里是其中的一个。今天太累了先写这点你看看,如果还有问题明天继续讨论。