假設你有一個命令如下:命令模式問題;需要澄清; Java的
public class PublishLastFiveCommand implements Command {
private Producer p;
public PublishLastFiveCommand(Producer p) {
this.p = p;
}
public void execute() {\
p.publishLastFive();
}
}
此外製片人讓你
public void publishLastFive() {
System.out.println("publishing last 5");
}
Command c;
public void setCommand(Command c) {
this.c = c;
}
public void execute() {
c.execute();
}
問:
預期用法是:
Command publish5 = new PublishLastFiveCommand(p);
p.setCommand(publish5);
p.execute();
是有一個對我來說,防止優雅的方式:
p.publishLastFive()
直接叫什麼名字?