diff --git a/notes/pics/command-remote.png b/notes/pics/command-remote.png new file mode 100644 index 00000000..b3693b6a Binary files /dev/null and b/notes/pics/command-remote.png differ diff --git a/notes/设计模式 - 命令.md b/notes/设计模式 - 命令.md index 2846cdbd..a5fea7fe 100644 --- a/notes/设计模式 - 命令.md +++ b/notes/设计模式 - 命令.md @@ -22,7 +22,7 @@ 设计一个遥控器,可以控制电灯开关。 -

+

```java public interface Command { diff --git a/tools/diagram/src/command-remote.svg b/tools/diagram/src/command-remote.svg new file mode 100644 index 00000000..369780ef --- /dev/null +++ b/tools/diagram/src/command-remote.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + 命令:遥控器只认 Command 接口 + + Invoker(遥控器) + + on[0] + + off[0] + + on[1] + + off[1] + + on[2] + + off[2] + + on[3] + + off[3] + + LightOnCommand + + execute() { light.on(); } + + LightOffCommand + + execute() { light.off(); } + + Light(接收者) + + on() + off() + + + + + + onButtonWasPushed(0) 只调用 onCommands[0].execute(),不知道背后是电灯还是空调;换一个命令对象,按钮就有了新功能。 +