auto commit
This commit is contained in:
parent
c1ff73a5b2
commit
7b91ea78f4
100
notes/设计模式.md
100
notes/设计模式.md
|
@ -1,31 +1,33 @@
|
||||||
<!-- GFM-TOC -->
|
<!-- GFM-TOC -->
|
||||||
* [一、概述](#一概述)
|
* [一、概述](#一概述)
|
||||||
* [二、创建型](#二创建型)
|
* [二、创建型](#二创建型)
|
||||||
* [1. 单例模式](#1-单例模式)
|
* [1. 单例(Singleton)](#1-单例singleton)
|
||||||
* [2. 简单工厂](#2-简单工厂)
|
* [2. 简单工厂(Simple Factory)](#2-简单工厂simple-factory)
|
||||||
* [3. 工厂方法模式](#3-工厂方法模式)
|
* [3. 工厂方法(Factory Method)](#3-工厂方法factory-method)
|
||||||
* [4. 抽象工厂模式](#4-抽象工厂模式)
|
* [4. 抽象工厂(Abstract Factory)](#4-抽象工厂abstract-factory)
|
||||||
* [5. 生成器](#5-生成器)
|
* [5. 生成器(Builder)](#5-生成器builder)
|
||||||
* [6. 原型模式](#6-原型模式)
|
* [6. 原型模式(Prototype)](#6-原型模式prototype)
|
||||||
* [三、行为型](#三行为型)
|
* [三、行为型](#三行为型)
|
||||||
* [1. 责任链](#1-责任链)
|
* [1. 责任链(Chain Of Responsibility)](#1-责任链chain-of-responsibility)
|
||||||
* [2. 命令模式](#2-命令模式)
|
* [2. 命令(Command)](#2-命令command)
|
||||||
* [3. 解释器模式](#3-解释器模式)
|
* [3. 解释器(Interpreter)](#3-解释器interpreter)
|
||||||
* [4. 迭代器](#4-迭代器)
|
* [4. 迭代器(Iterator)](#4-迭代器iterator)
|
||||||
* [5. 中间人模式](#5-中间人模式)
|
* [5. 中介者(Mediator)](#5-中介者mediator)
|
||||||
* [6. 备忘录模式](#6-备忘录模式)
|
* [6. 备忘录(Memento)](#6-备忘录memento)
|
||||||
* [7. 观察者模式](#7-观察者模式)
|
* [7. 观察者(Observer)](#7-观察者observer)
|
||||||
* [8. 策略模式](#8-策略模式)
|
* [8. 状态(State)](#8-状态state)
|
||||||
* [9. 模板方法](#9-模板方法)
|
* [9. 策略(Strategy)](#9-策略strategy)
|
||||||
* [10. 访问者模式](#10-访问者模式)
|
* [10. 模板方法(Template Method)](#10-模板方法template-method)
|
||||||
* [11. 空对象模式](#11-空对象模式)
|
* [11. 访问者(Visitor)](#11-访问者visitor)
|
||||||
|
* [12. 空对象(Null)](#12-空对象null)
|
||||||
* [四、结构型](#四结构型)
|
* [四、结构型](#四结构型)
|
||||||
* [1. 适配器模式](#1-适配器模式)
|
* [1. 适配器(Adapter)](#1-适配器adapter)
|
||||||
* [2. 桥接模式](#2-桥接模式)
|
* [2. 桥接(Bridge)](#2-桥接bridge)
|
||||||
* [3. 组合模式](#3-组合模式)
|
* [3. 组合(Composite)](#3-组合composite)
|
||||||
* [4. 装饰者模式](#4-装饰者模式)
|
* [4. 装饰(Decorator)](#4-装饰decorator)
|
||||||
* [5. 蝇量模式](#5-蝇量模式)
|
* [5. 外观(Facade)](#5-外观facade)
|
||||||
* [6. 动态代理](#6-动态代理)
|
* [6. 享元(Flyweight)](#6-享元flyweight)
|
||||||
|
* [7. 代理(Proxy)](#7-代理proxy)
|
||||||
* [参考资料](#参考资料)
|
* [参考资料](#参考资料)
|
||||||
<!-- GFM-TOC -->
|
<!-- GFM-TOC -->
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@
|
||||||
|
|
||||||
# 二、创建型
|
# 二、创建型
|
||||||
|
|
||||||
## 1. 单例模式
|
## 1. 单例(Singleton)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ public class Singleton implements Serializable{
|
||||||
- [java.awt.Desktop#getDesktop()](http://docs.oracle.com/javase/8/docs/api/java/awt/Desktop.html#getDesktop--)
|
- [java.awt.Desktop#getDesktop()](http://docs.oracle.com/javase/8/docs/api/java/awt/Desktop.html#getDesktop--)
|
||||||
- [java.lang.System#getSecurityManager()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getSecurityManager--)
|
- [java.lang.System#getSecurityManager()](http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getSecurityManager--)
|
||||||
|
|
||||||
## 2. 简单工厂
|
## 2. 简单工厂(Simple Factory)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -269,7 +271,7 @@ public class Client {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. 工厂方法模式
|
## 3. 工厂方法(Factory Method)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -329,7 +331,7 @@ public class ConcreteFactory2 extends Factory {
|
||||||
- [java.util.EnumSet](https://docs.oracle.com/javase/8/docs/api/java/util/EnumSet.html#of-E-)
|
- [java.util.EnumSet](https://docs.oracle.com/javase/8/docs/api/java/util/EnumSet.html#of-E-)
|
||||||
- [javax.xml.bind.JAXBContext](https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXBContext.html#createMarshaller--)
|
- [javax.xml.bind.JAXBContext](https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXBContext.html#createMarshaller--)
|
||||||
|
|
||||||
## 4. 抽象工厂模式
|
## 4. 抽象工厂(Abstract Factory)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -427,7 +429,7 @@ public class Client {
|
||||||
- [javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
|
- [javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
|
||||||
- [javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
|
- [javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
|
||||||
|
|
||||||
## 5. 生成器
|
## 5. 生成器(Builder)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -443,7 +445,7 @@ public class Client {
|
||||||
- [java.lang.Appendable](http://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html)
|
- [java.lang.Appendable](http://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html)
|
||||||
- [Apache Camel builders](https://github.com/apache/camel/tree/0e195428ee04531be27a0b659005e3aa8d159d23/camel-core/src/main/java/org/apache/camel/builder)
|
- [Apache Camel builders](https://github.com/apache/camel/tree/0e195428ee04531be27a0b659005e3aa8d159d23/camel-core/src/main/java/org/apache/camel/builder)
|
||||||
|
|
||||||
## 6. 原型模式
|
## 6. 原型模式(Prototype)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -455,7 +457,7 @@ public class Client {
|
||||||
|
|
||||||
# 三、行为型
|
# 三、行为型
|
||||||
|
|
||||||
## 1. 责任链
|
## 1. 责任链(Chain Of Responsibility)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -467,7 +469,7 @@ public class Client {
|
||||||
- [Apache Commons Chain](https://commons.apache.org/proper/commons-chain/index.html)
|
- [Apache Commons Chain](https://commons.apache.org/proper/commons-chain/index.html)
|
||||||
- [javax.servlet.Filter#doFilter()](http://docs.oracle.com/javaee/7/api/javax/servlet/Filter.html#doFilter-javax.servlet.ServletRequest-javax.servlet.ServletResponse-javax.servlet.FilterChain-)
|
- [javax.servlet.Filter#doFilter()](http://docs.oracle.com/javaee/7/api/javax/servlet/Filter.html#doFilter-javax.servlet.ServletRequest-javax.servlet.ServletResponse-javax.servlet.FilterChain-)
|
||||||
|
|
||||||
## 2. 命令模式
|
## 2. 命令(Command)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -479,7 +481,7 @@ public class Client {
|
||||||
- [Netflix Hystrix](https://github.com/Netflix/Hystrix/wiki)
|
- [Netflix Hystrix](https://github.com/Netflix/Hystrix/wiki)
|
||||||
- [javax.swing.Action](http://docs.oracle.com/javase/8/docs/api/javax/swing/Action.html)
|
- [javax.swing.Action](http://docs.oracle.com/javase/8/docs/api/javax/swing/Action.html)
|
||||||
|
|
||||||
## 3. 解释器模式
|
## 3. 解释器(Interpreter)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -492,7 +494,7 @@ public class Client {
|
||||||
- All subclasses of [java.text.Format](http://docs.oracle.com/javase/8/docs/api/java/text/Format.html)
|
- All subclasses of [java.text.Format](http://docs.oracle.com/javase/8/docs/api/java/text/Format.html)
|
||||||
- [javax.el.ELResolver](http://docs.oracle.com/javaee/7/api/javax/el/ELResolver.html)
|
- [javax.el.ELResolver](http://docs.oracle.com/javaee/7/api/javax/el/ELResolver.html)
|
||||||
|
|
||||||
## 4. 迭代器
|
## 4. 迭代器(Iterator)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -580,7 +582,7 @@ public class Client {
|
||||||
- [java.util.Iterator](http://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html)
|
- [java.util.Iterator](http://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html)
|
||||||
- [java.util.Enumeration](http://docs.oracle.com/javase/8/docs/api/java/util/Enumeration.html)
|
- [java.util.Enumeration](http://docs.oracle.com/javase/8/docs/api/java/util/Enumeration.html)
|
||||||
|
|
||||||
## 5. 中间人模式
|
## 5. 中介者(Mediator)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -594,7 +596,7 @@ public class Client {
|
||||||
- scheduleXXX() methods of [java.util.concurrent.ScheduledExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html)
|
- scheduleXXX() methods of [java.util.concurrent.ScheduledExecutorService](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html)
|
||||||
- [java.lang.reflect.Method#invoke()](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...-)
|
- [java.lang.reflect.Method#invoke()](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...-)
|
||||||
|
|
||||||
## 6. 备忘录模式
|
## 6. 备忘录(Memento)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -604,7 +606,7 @@ public class Client {
|
||||||
|
|
||||||
- [java.util.Date](http://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
|
- [java.util.Date](http://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
|
||||||
|
|
||||||
## 7. 观察者模式
|
## 7. 观察者(Observer)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -742,7 +744,9 @@ StatisticsDisplay.update: 1.0 1.0 1.0
|
||||||
- [javax.servlet.http.HttpSessionBindingListener](http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpSessionBindingListener.html)
|
- [javax.servlet.http.HttpSessionBindingListener](http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpSessionBindingListener.html)
|
||||||
- [RxJava](https://github.com/ReactiveX/RxJava)
|
- [RxJava](https://github.com/ReactiveX/RxJava)
|
||||||
|
|
||||||
## 8. 策略模式
|
## 8. 状态(State)
|
||||||
|
|
||||||
|
## 9. 策略(Strategy)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -824,7 +828,7 @@ quack!
|
||||||
- javax.servlet.http.HttpServlet
|
- javax.servlet.http.HttpServlet
|
||||||
- javax.servlet.Filter#doFilter()
|
- javax.servlet.Filter#doFilter()
|
||||||
|
|
||||||
## 9. 模板方法
|
## 10. 模板方法(Template Method)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -925,7 +929,7 @@ Tea.addCondiments
|
||||||
- java.io.InputStream#read()
|
- java.io.InputStream#read()
|
||||||
- java.util.AbstractList#indexOf()
|
- java.util.AbstractList#indexOf()
|
||||||
|
|
||||||
## 10. 访问者模式
|
## 11. 访问者(Visitor)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -938,7 +942,7 @@ Tea.addCondiments
|
||||||
- javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor
|
- javax.lang.model.element.Element and javax.lang.model.element.ElementVisitor
|
||||||
- javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor
|
- javax.lang.model.type.TypeMirror and javax.lang.model.type.TypeVisitor
|
||||||
|
|
||||||
## 11. 空对象模式
|
## 12. 空对象(Null)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -995,7 +999,7 @@ public class Client {
|
||||||
|
|
||||||
# 四、结构型
|
# 四、结构型
|
||||||
|
|
||||||
## 1. 适配器模式
|
## 1. 适配器(Adapter)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1066,7 +1070,7 @@ public class Client {
|
||||||
- [java.util.Collections#enumeration()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#enumeration-java.util.Collection-)
|
- [java.util.Collections#enumeration()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#enumeration-java.util.Collection-)
|
||||||
- [javax.xml.bind.annotation.adapters.XMLAdapter](http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-)
|
- [javax.xml.bind.annotation.adapters.XMLAdapter](http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-)
|
||||||
|
|
||||||
## 2. 桥接模式
|
## 2. 桥接(Bridge)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1077,7 +1081,7 @@ public class Client {
|
||||||
- AWT (It provides an abstraction layer which maps onto the native OS the windowing support.)
|
- AWT (It provides an abstraction layer which maps onto the native OS the windowing support.)
|
||||||
- JDBC
|
- JDBC
|
||||||
|
|
||||||
## 3. 组合模式
|
## 3. 组合(Composite)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1215,7 +1219,7 @@ Composite:root
|
||||||
- java.util.List#addAll(Collection)
|
- java.util.List#addAll(Collection)
|
||||||
- java.util.Set#addAll(Collection)
|
- java.util.Set#addAll(Collection)
|
||||||
|
|
||||||
## 4. 装饰者模式
|
## 4. 装饰(Decorator)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1320,7 +1324,9 @@ public class Client {
|
||||||
- java.util.zip.ZipOutputStream(OutputStream)
|
- java.util.zip.ZipOutputStream(OutputStream)
|
||||||
- java.util.Collections#checked[List|Map|Set|SortedSet|SortedMap]()
|
- java.util.Collections#checked[List|Map|Set|SortedSet|SortedMap]()
|
||||||
|
|
||||||
## 5. 蝇量模式
|
## 5. 外观(Facade)
|
||||||
|
|
||||||
|
## 6. 享元(Flyweight)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1335,7 +1341,7 @@ Java 利用缓存来加速大量小对象的访问时间。
|
||||||
- java.lang.Byte#valueOf(byte)
|
- java.lang.Byte#valueOf(byte)
|
||||||
- java.lang.Character#valueOf(char)
|
- java.lang.Character#valueOf(char)
|
||||||
|
|
||||||
## 6. 动态代理
|
## 7. 代理(Proxy)
|
||||||
|
|
||||||
### 意图
|
### 意图
|
||||||
|
|
||||||
|
@ -1351,6 +1357,8 @@ Java 利用缓存来加速大量小对象的访问时间。
|
||||||
# 参考资料
|
# 参考资料
|
||||||
|
|
||||||
- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007.
|
- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007.
|
||||||
|
- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.
|
||||||
|
- Bloch J. Effective java[M]. Addison-Wesley Professional, 2017.
|
||||||
- [Design Patterns](http://www.oodesign.com/)
|
- [Design Patterns](http://www.oodesign.com/)
|
||||||
- [Design patterns implemented in Java](http://java-design-patterns.com/)
|
- [Design patterns implemented in Java](http://java-design-patterns.com/)
|
||||||
- [The breakdown of design patterns in JDK](http://www.programering.com/a/MTNxAzMwATY.html)
|
- [The breakdown of design patterns in JDK](http://www.programering.com/a/MTNxAzMwATY.html)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user