# Go 语言设计模式
<div align="center">
<img src="./gopher.png" width=20%>
</div>
Go 语言设计模式的实现代码,[Quick Start](./tutorial/tutorial.md)。
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- [图解设计模式分类](#%E5%9B%BE%E8%A7%A3%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E5%88%86%E7%B1%BB)
- [适应设计模式](#%E9%80%82%E5%BA%94%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)
- [交给子类](#%E4%BA%A4%E7%BB%99%E5%AD%90%E7%B1%BB)
- [生成实例](#%E7%94%9F%E6%88%90%E5%AE%9E%E4%BE%8B)
- [分开考虑](#%E5%88%86%E5%BC%80%E8%80%83%E8%99%91)
- [一致性](#%E4%B8%80%E8%87%B4%E6%80%A7)
- [访问数据结构](#%E8%AE%BF%E9%97%AE%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84)
- [简单化](#%E7%AE%80%E5%8D%95%E5%8C%96)
- [管理状态](#%E7%AE%A1%E7%90%86%E7%8A%B6%E6%80%81)
- [避免浪费](#%E9%81%BF%E5%85%8D%E6%B5%AA%E8%B4%B9)
- [用类来实现](#%E7%94%A8%E7%B1%BB%E6%9D%A5%E5%AE%9E%E7%8E%B0)
- [GoF 设计模式分类](#gof-%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E5%88%86%E7%B1%BB)
- [创建型设计模式](#%E5%88%9B%E5%BB%BA%E5%9E%8B%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)
- [结构性设计模式](#%E7%BB%93%E6%9E%84%E6%80%A7%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)
- [行为型设计模式](#%E8%A1%8C%E4%B8%BA%E5%9E%8B%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F)
- [感谢](#%E6%84%9F%E8%B0%A2)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## 图解设计模式分类
### 适应设计模式
- [Iterator 模式(迭代器模式)](./01_iterator/):一个一个遍历
- [Adapter 模式(适配器模式)](./02_adapter/):加个 “适配器” 以便于复用
### 交给子类
- [Template Method 模式(模板方法模式)](./03_template_method/):将具体处理交给子类
- [Factory Method 模式(工厂方法模式)](./04_factory_method/):将实例的生成交给子类
### 生成实例
- [SingleTon 模式(单例模式)](./05_singleton/):只有一个实例
- [Prototype 模式(原型模式)](./06_prototype/):通过复制生成实例
- [Builder 模式(建造者模式)](./07_builder/):组装复杂的实例
- [Abstract Factory 模式(抽象工厂模式)](./08_abstract_factory/):将关联零件组装成产品
### 分开考虑
- [Bridge 模式(桥接模式)](./09_bridge/):将类的功能层次结构与实现层次结构分离
- [Strategy 模式(策略模式)](./10_strategy/):整体地替换算法
### 一致性
- [Composite 模式(组合模式)](./11_composite/):容器与内容的一致性
- [Decorator 模式(装饰模式)](./12_decorator/):装饰边框与被装饰物的一致性
### 访问数据结构
- [Visitor 模式(访问者模式)](./13_visitor/):访问数据结构并处理数据
- [Chain of Responsibility 模式(责任链模式)](./14_chain_of_responsibility/):推卸责任
### 简单化
- [Facade 模式(外观模式)](./15_facade/):简单窗口
- [Mediator 模式(中介者模式)](./16_mediator/):只有一个仲裁者
### 管理状态
- [Observer 模式(观察者模式)](./17_observer/):发送状态变化通知
- [Memento 模式(备忘录模式)](./18_memento/):保存对象状态
- [State 模式(状态模式)](./19_state/):用类表示状态
### 避免浪费
- [Flyweight 模式(享元模式)](./20_flyweight/):共享对象,避免浪费
- [Proxy 模式(代理模式)](./21_proxy/):只在必要时生成实例
### 用类来实现
- [Command 模式(命令模式)](./22_command/):命令也是类
- [Interpreter 模式(解释器模式)](./23_interpreter/):语法规则也是类
## GoF 设计模式分类
### 创建型设计模式
- [Abstract Factory 模式(抽象工厂模式)](./08_abstract_factory/)
- [Builder 模式(建造者模式)](./07_builder/)
- [Factory Method 模式(工厂方法模式)](./04_factory_method/)
- [Prototype 模式(原型模式)](./06_prototype/)
- [SingleTon 模式(单例模式)](./05_singleton/)
### 结构性设计模式
- [Adapter 模式(适配器模式)](./02_adapter/)
- [Bridge 模式(桥接模式)](./09_bridge/)
- [Composite 模式(组合模式)](./11_composite/)
- [Decorator 模式(装饰模式)](./12_decorator/)
- [Facade 模式(外观模式)](./15_facade/)
- [Flyweight 模式(享元模式)](./20_flyweight/)
- [Proxy 模式(代理模式)](./21_proxy/)
### 行为型设计模式
- [Chain of Responsibility 模式(责任链模式)](./14_chain_of_responsibility/)
- [Command 模式(命令模式)](./22_command/)
- [Interpreter 模式(解释器模式)](./23_interpreter/)
- [Iterator 模式(迭代器模式)](./01_iterator/)
- [Mediator 模式(中介者模式)](./16_mediator/)
- [Memento 模式(备忘录模式)](./18_memento/)
- [Observer 模式(观察者模式)](./17_observer/)
- [State 模式(状态模式)](./19_state/)
- [Strategy 模式(策略模式)](./10_strategy/)
- [Template Method 模式(模板方法模式)](./03_template_method/)
- [Visitor 模式(访问者模式)](./13_visitor)
## 感谢
一直都想学习设计模式,但也只是想了,直到被 [vasily](https://www.vasily.cool/) 刺激 `你能别写哈巴代码了吗`,于是痛定思痛买了本[图解设计模式](https://book.douban.com/subject/26933281/)研读。~~由于平时又忙,周末又懒,~~ 断断续续看了一个半月,终于读完了。收获很多,系统的了解了 GoF 设计模式,Golang 的使用也有所进步(可能),但离写出非常漂亮的代码还有段距离,用书中的话与大家共勉,**Enjoy Patterns!**
本 repo 参考了 [senghoo/golang-design-pattern](https://github.com/senghoo/golang-design-pattern) 的项目结构,代码实现和类图参考了 [Refactoring.Guru 设计模式](https://refactoringguru.cn/design-patterns)。
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
读书笔记:《图解设计模式》读书笔记.zip (169个子文件)
config 261B
FETCH_HEAD 249B
.gitignore 325B
memento_test.go 14KB
mediator.go 4KB
interpreter.go 4KB
abstract_factory.go 4KB
state.go 3KB
strategy.go 2KB
builder.go 2KB
chain_of_responsibility.go 2KB
decorator.go 2KB
observer.go 2KB
visitor.go 2KB
facade.go 2KB
mediator_test.go 2KB
memento.go 2KB
prototype.go 1KB
bridge.go 1KB
composite_test.go 1KB
visitor_test.go 1KB
proxy.go 1KB
flyweight.go 1KB
iterator.go 1KB
command.go 1KB
flyweight_test.go 1KB
chain_of_responsibility_test.go 1KB
hand.go 1KB
composite.go 1KB
template_method.go 1KB
factory_method.go 1KB
observer_test.go 1KB
state_test.go 1KB
strategy_test.go 1KB
abstract_factory_test.go 1016B
command_test.go 986B
interpreter_test.go 833B
decorator_test.go 800B
bridge_test.go 732B
builder_test.go 712B
adapter.go 671B
prototype_test.go 658B
template_method_test.go 546B
iterator_test.go 501B
factory_method_test.go 469B
proxy_test.go 452B
singleton_test.go 388B
stack.go 379B
trouble.go 305B
singleton.go 277B
action_event.go 211B
adapter_test.go 190B
facade_test.go 169B
HEAD 130B
HEAD 21B
LinkPage.html 577B
welcome.html 263B
Greeting.html 245B
pack-3aa9000260d079e074deb0cadd3a9aa6a5addd29.idx 12KB
index 14KB
LICENSE 1KB
main 144B
main 130B
main 41B
README.md 6KB
tutorial.md 2KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 1KB
README.md 999B
README.md 982B
README.md 920B
README.md 881B
README.md 871B
README.md 837B
README.md 810B
README.md 798B
README.md 796B
README.md 718B
README.md 684B
README.md 400B
go.mod 58B
pack-3aa9000260d079e074deb0cadd3a9aa6a5addd29.pack 1.98MB
packed-refs 147B
gopher.png 212KB
abstract_factory.png 98KB
mediator_class.png 73KB
bridge.png 70KB
observer.png 67KB
state_class.png 57KB
decorator.png 54KB
command_class.png 50KB
共 169 条
- 1
- 2
资源评论
九转成圣
- 粉丝: 3764
- 资源: 2961
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功