Skip to content

Commit 322bc27

Browse files
authored
Create README.md
1 parent 44c19f8 commit 322bc27

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

State/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# State
2+
3+
## 动机(Motivation)
4+
+ 对象状态如果改变,其行为也会随之而发生变化,比如文档处于只读状态,其支持的行为和读写状态支持的行为就可能完全不同。
5+
+ 如何在运行时根据对象的状态来透明地改变对象的行为?
6+
7+
8+
## 模式定义
9+
允许一个对象在其内部状态改变时改变它的行为。从而使对象看起来似乎修改了其行为。
10+
——《设计模式》GoF
11+
12+
## 要点总结
13+
+ State模式将所有与一个特定状态相关的行为都放入一个State的子对象中,在对象状态切换时,切换相应的对象;
14+
但同时维持State的接口,这样实现了具体操作与状态转换之间的解耦。
15+
+ 转换是原子性的
16+
+ 与Strategy模式类似

0 commit comments

Comments
 (0)