-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
### 状态模式(State Pattern) | ||
|
||
##### 行为模式(Behavioural Pattern) | ||
|
||
#### 定义 | ||
|
||
***Ties object circumstances to its behavior, allowing the object to behave in different ways based upon its internal state.*** | ||
|
||
***定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。*** | ||
|
||
![Visitor Pattern UML](../images/template_method.png) | ||
|
||
|
||
|
||
### 优点 | ||
1. 封装和控制了业务的不变部分。 | ||
2. 实现代码复用,将公共功能部分代码抽取出来,更易于维护。 | ||
|
||
### 例子分析 | ||
|
||
##### 下载工具案例 | ||
|
||
### 参考文档: | ||
|
||
https://en.wikipedia.org/wiki/Template_method_pattern | ||
|
||
https://dzone.com/articles/design-patterns-template-method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package state | ||
|
||
import "fmt" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
|