Suppose you have a command as follows:
public class PublishLastFiveCommand implements Command {
private Producer p;
public PublishLastFiveCommand(Producer p) {
this.p = p;
}
public void execute() {\
p.publishLastFive();
}
}
Additionally producer allows you to
public void publishLastFive() {
System.out.println("publishing last 5");
}
Command c;
public void setCommand(Command c) {
this.c = c;
}
public void execute() {
c.execute();
}
Question:
Intended usage is:
Command publish5 = new PublishLastFiveCommand(p);
p.setCommand(publish5);
p.execute();
Is there a graceful way for me to protect against:
p.publishLastFive()
being called directly?