diff --git a/notes/pics/dp-state.png b/notes/pics/dp-state.png new file mode 100644 index 00000000..26fad840 Binary files /dev/null and b/notes/pics/dp-state.png differ diff --git a/notes/设计模式 - 状态.md b/notes/设计模式 - 状态.md index 3fac013b..a863b47a 100644 --- a/notes/设计模式 - 状态.md +++ b/notes/设计模式 - 状态.md @@ -1,15 +1,12 @@ ## 8. 状态(State) -### Intent - +### 意图 允许对象在内部状态改变时改变它的行为,对象看起来好像修改了它所属的类。 -### Class Diagram - -

- -### Implementation +### 类图 +

+### 实现 糖果销售机有多种状态,每种状态下销售机有不同的行为,状态可以发生转移,使得销售机的行为也发生改变。

@@ -272,7 +269,7 @@ public class Client { } ``` -```html +```text You insert a quarter You turned... A gumball comes rolling out the slot... @@ -299,3 +296,8 @@ You can't insert a quarter, the machine is sold out You turned, but there are no gumballs No gumball dispensed ``` + +## 参考资料 + +- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007. +- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.