您的位置:首页 > 大数据 > 人工智能

Design Pattern Explained

2015-07-09 04:13 471 查看
The Command Pattern:

encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations

public interface Command {
public void execute();
}

public class LightOnCommand implements Command {
Light light;

public LightOnCommand(Light light) {
this.light = light;
}

public void execute() {
light.on();
}
}

public class RemoteControl {
Command slot;

public RemoteControl() {}

public void setCommand(Command slot) {
this.slot = slot;
}

public void buttonPressed() {
slot.execute();
}
}


x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: