Skip to content

Commit

Permalink
add state pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
nox60 committed Dec 4, 2019
1 parent 7c723e3 commit 890429f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
Binary file added images/state_pattern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions state/README.MD
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
2 changes: 1 addition & 1 deletion state/state.go → state/stateExample/state/state.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package state

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion state/state2.go → state/stateExample/state/state2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package state

import (
"fmt"
Expand Down

0 comments on commit 890429f

Please sign in to comment.