diff --git a/notes/pics/dp-command.png b/notes/pics/dp-command.png new file mode 100644 index 00000000..19bcc218 Binary files /dev/null and b/notes/pics/dp-command.png differ diff --git a/notes/设计模式 - 命令.md b/notes/设计模式 - 命令.md index a5fea7fe..4fe0fdef 100644 --- a/notes/设计模式 - 命令.md +++ b/notes/设计模式 - 命令.md @@ -1,7 +1,6 @@ ## 2. 命令(Command) -### Intent - +### 意图 将命令封装成对象中,具有以下作用: - 使用命令来参数化其它对象 @@ -9,17 +8,15 @@ - 将命令的操作记录到日志中 - 支持可撤销的操作 -### Class Diagram - +### 类图 - Command:命令 - Receiver:命令接收者,也就是命令真正的执行者 - Invoker:通过它来调用命令 - Client:可以设置命令与命令的接收者 -

- -### Implementation +

+### 实现 设计一个遥控器,可以控制电灯开关。

@@ -120,8 +117,12 @@ public class Client { } ``` -### JDK - +### JDK 中的应用 - [java.lang.Runnable](http://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html) - [Netflix Hystrix](https://github.com/Netflix/Hystrix/wiki) - [javax.swing.Action](http://docs.oracle.com/javase/8/docs/api/javax/swing/Action.html) + +## 参考资料 + +- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007. +- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.