Design Architecture/Design Pattern 예제
Commnad패턴 예제
lipnus
2022. 4. 26. 10:45
반응형
public interface Command {
public void excute();
}
public class LightOnCommand implements Command {
Light light; // Light: 리시버
public LightOnCommand(Light light) {
this.light = light;
}
public void excute() {
light.on();
}
}
public class SimpleRemoteControl {
Command slot;
public SimpleRemoteControl() {}
public void setCommand(Command command) {
this.slot = command;
}
public void buttonWasPressed() {
slot.excute();
}
}
public class RemoteControlTest {
public static void main(String[] args) {
SimpleRemoteControl remote = new SimpleRemoteControl(); // 인보커(종업원)
Light light = new Light(); // 리시버(주방장)
LightOnCommand command = new LightOnCommand(light);
remote.set(command);
remote.buttonWasPressed();
}
}
반응형