二十三种设计模式
2018-03-26 本文已影响1175人
仕明同学
DesignPattern
下载地址
![](https://img.haomeiwen.com/i5363507/b1e758b10efca33a.png)
每个设计模式写了一个例子,同时也上传了xmind和图片!偷偷报告下,github上的图片更加的清晰!可以把项目fork到本地,顺带来个小星星,☺☺☺
![](https://img.haomeiwen.com/i5363507/06a9019af7cb162c.png)
- 创建型模式,共五种:工厂方法模式、抽象工厂模式、单例模式、建造者模式、原型模式。
- 结构型模式,共七种:适配器模式、装饰器模式、代理模式、外观模式、桥接模式、组合模式、享元模式。
- 行为型模式,共十一种:策略模式、模板方法模式、观察者模式、迭代子模式、责任链模式、
命令模式、备忘录模式、状态模式、访问者模式、中介者模式、解释器模式。
正如《设计模式》的作者GoF(《Design Patterns: Elements of Reusable Object-Oriented Software》(即后述《设计模式》一书),由 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides 合著(Addison-Wesley,1995)。这几位作者常被称为"四人组(Gang of Four)对访问者模式的描述:大多数情况下,你并需要使用访问者模式,但是当你一旦需要使用它时,那你就是真的需要它了。当然这只是针对真正的大牛而言。在现实情况下(至少是我所处的环境当中),很多人往往沉迷于设计模式,他们使用一种设计模式时, 从来不去认真考虑所使用的模式是否适合这种场景,而往往只是想展示一下自己对面向对象设计的驾驭能力。编程时有这种心理,往往会发生滥用设计模式的情况。所以,在学习设计模式时,一定要理解模式的适用性。必须做到使用一种模式是因为了解它的优点, 不使用一种模式是因为了解它的弊端;而不是使用一种模式是因为不了解它的弊端,不使用一种模式是因为不了解它的优点。
-
行为型模式start 共十一种
Visitor访问者模式.png
![](https://img.haomeiwen.com/i5363507/2b80c325c00f1be9.png)
![](https://img.haomeiwen.com/i5363507/fde040ed2eca4371.png)
![](https://img.haomeiwen.com/i5363507/2381fd97769e7e7b.png)
![](https://img.haomeiwen.com/i5363507/476c8bb17b124d22.png)
![](https://img.haomeiwen.com/i5363507/9b2e6173558a8167.png)
![](https://img.haomeiwen.com/i5363507/acbf7b7ec9862284.png)
![](https://img.haomeiwen.com/i5363507/f5adb5c7246883c6.png)
![](https://img.haomeiwen.com/i5363507/911ada461ccd1045.png)
![](https://img.haomeiwen.com/i5363507/581fa7107b9dc928.png)
![](https://img.haomeiwen.com/i5363507/e5bcbeb88858daee.png)
- 行为型模式end
-
创建型模式start 共五种,我把抽象工厂和工厂模式合在一起了
BuildPattern建造者模式.png
![](https://img.haomeiwen.com/i5363507/745f2302912101fb.png)
![](https://img.haomeiwen.com/i5363507/8bfb6de23172a226.png)
![](https://img.haomeiwen.com/i5363507/1b03ad0bc20efcf7.png)
-
创建型模式end
-
结构型模式start 共七种
![](https://img.haomeiwen.com/i5363507/9aa7f9dc737714ab.png)
![](https://img.haomeiwen.com/i5363507/b0473004c41d9310.png)
![](https://img.haomeiwen.com/i5363507/f00c7b8898922f27.png)
![](https://img.haomeiwen.com/i5363507/33655004343d8662.png)
![](https://img.haomeiwen.com/i5363507/b576c5de2a3093a0.png)
![](https://img.haomeiwen.com/i5363507/81ac0398e2e161dd.png)
![](https://img.haomeiwen.com/i5363507/7686ba5bea2d4dc0.png)
- 结构型模式start end