mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 15:13:44 +00:00
Update 设计模式 - 状态.md
小节标题改为中文,重新绘制类图,补充参考资料。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 272 KiB |
+10
-8
@@ -1,15 +1,12 @@
|
||||
## 8. 状态(State)
|
||||
|
||||
### Intent
|
||||
|
||||
### 意图
|
||||
允许对象在内部状态改变时改变它的行为,对象看起来好像修改了它所属的类。
|
||||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/79df886f-fdc3-4020-a07f-c991bb58e0d8.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
### 类图
|
||||
<div align="center"> <img src="pics/dp-state.png" width="760px"/> </div><br>
|
||||
|
||||
### 实现
|
||||
糖果销售机有多种状态,每种状态下销售机有不同的行为,状态可以发生转移,使得销售机的行为也发生改变。
|
||||
|
||||
<div align="center"> <img src="pics/state-gumball.png" width="740px"/> </div><br>
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user