auto commit
|
@ -54,7 +54,7 @@
|
|||
|
||||
私有构造函数保证了不能通过构造函数来创建对象实例,只能通过公有静态函数返回唯一的私有静态变量。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/562f2844-d77c-40e0-887a-28a7128abd42.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/eca1f422-8381-409b-ad04-98ef39ae38ba.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -255,7 +255,7 @@ secondName
|
|||
|
||||
这样做能把客户类和具体子类的实现解耦,客户类不再需要知道有哪些子类以及应当实例化哪个子类。客户类往往有多个,如果不使用简单工厂,那么所有的客户类都要知道所有子类的细节。而且一旦子类发生改变,例如增加子类,那么所有的客户类都要进行修改。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c79da808-0f28-4a36-bc04-33ccc5b83c13.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/40c0c17e-bba6-4493-9857-147c0044a018.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -338,7 +338,7 @@ public class Client {
|
|||
|
||||
下图中,Factory 有一个 doSomething() 方法,这个方法需要用到一个产品对象,这个产品对象由 factoryMethod() 方法创建。该方法是抽象的,需要由子类去实现。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/1818e141-8700-4026-99f7-900a545875f5.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/f4d0afd0-8e78-4914-9e60-4366eaf065b5.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -402,7 +402,7 @@ public class ConcreteFactory2 extends Factory {
|
|||
|
||||
从高层次来看,抽象工厂使用了组合,即 Cilent 组合了 AbstractFactory,而工厂方法模式使用了继承。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/8668a3e1-c9c7-4fcb-98b2-a96a5d841579.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/e2190c36-8b27-4690-bde5-9911020a1294.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -492,7 +492,7 @@ public class Client {
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/13b0940e-d1d7-4b17-af4f-b70cb0a75e08.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/db5e376d-0b3e-490e-a43a-3231914b6668.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -582,7 +582,7 @@ abcdefghijklmnopqrstuvwxyz
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a40661e4-1a71-46d2-a158-ff36f7fc3331.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/b8922f8c-95e6-4187-be85-572a509afb71.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -643,7 +643,7 @@ abc
|
|||
|
||||
- Handler:定义处理请求的接口,并且实现后继链(successor)
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/691f11eb-31a7-46be-9de1-61f433c4b3c7.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ca9f23bf-55a4-47b2-9534-a28e35397988.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -781,7 +781,7 @@ request2 is handle by ConcreteHandler2
|
|||
- Invoker:通过它来调用命令
|
||||
- Client:可以设置命令与命令的接收者
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ae1b27b8-bc13-42e7-ac12-a2242e125499.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c44a0342-f405-4f17-b750-e27cf4aadde2.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -902,7 +902,7 @@ public class Client {
|
|||
- TerminalExpression:终结符表达式,每个终结符都需要一个 TerminalExpression。
|
||||
- Context:上下文,包含解释器之外的一些全局信息。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/794239e3-4baf-4aad-92df-f02f59b2a6fe.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/2b125bcd-1b36-43be-9b78-d90b076be549.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ false
|
|||
- Iterator 主要定义了 hasNext() 和 next() 方法。
|
||||
- Client 组合了 Aggregate,为了迭代遍历 Aggregate,也需要组合 Iterator。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/b0f61ac2-a4b6-4042-9cf0-ccf4238c1ff7.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/89292ae1-5f13-44dc-b508-3f035e80bf89.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1116,7 +1116,7 @@ public class Client {
|
|||
- Mediator:中介者,定义一个接口用于与各同事(Colleague)对象通信。
|
||||
- Colleague:同事,相关对象
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/d0afdd23-c9a5-4d1c-9b3d-404bff3bd0d1.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/30d6e95c-2e3c-4d32-bf4f-68128a70bc05.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1286,7 +1286,7 @@ doSprinkler()
|
|||
- Caretaker:负责保存好备忘录
|
||||
- Menento:备忘录,存储原始对象的的状态。备忘录实际上有两个接口,一个是提供给 Caretaker 的窄接口:它只能将备忘录传递给其它对象;一个是提供给 Originator 的宽接口,允许它访问到先前状态所需的所有数据。理想情况是只允许 Originator 访问本备忘录的内部状态。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/867e93eb-3161-4f39-b2d2-c0cd3788e194.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/50678f34-694f-45a4-91c6-34d985c83fee.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1467,7 +1467,7 @@ public class Client {
|
|||
|
||||
观察者(Observer)的注册功能需要调用主题的 registerObserver() 方法。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/0df5d84c-e7ca-4e3a-a688-bb8e68894467.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a8c8f894-a712-447c-9906-5caef6a016e3.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1594,7 +1594,7 @@ StatisticsDisplay.update: 1.0 1.0 1.0
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c5085437-54df-4304-b62d-44b961711ba7.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/79df886f-fdc3-4020-a07f-c991bb58e0d8.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ No gumball dispensed
|
|||
- Strategy 接口定义了一个算法族,它们都实现了 behavior() 方法。
|
||||
- Context 是使用到该算法族的类,其中的 doSomething() 方法会调用 behavior(),setStrategy(Strategy) 方法可以动态地改变 strategy 对象,也就是说能动态地改变 Context 所使用的算法。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/1fc969e4-0e7c-441b-b53c-01950d2f2be5.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/cd1be8c2-755a-4a66-ad92-2e30f8f47922.png"/> </div><br>
|
||||
|
||||
### 与状态模式的比较
|
||||
|
||||
|
@ -1988,7 +1988,7 @@ quack!
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c3c1c0e8-3a78-4426-961f-b46dd0879dd8.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ac6a794b-68c0-486c-902f-8d988eee5766.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2091,7 +2091,7 @@ Tea.addCondiments
|
|||
- ConcreteVisitor:具体访问者,存储遍历过程中的累计结果
|
||||
- ObjectStructure:对象结构,可以是组合结构,或者是一个集合。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ec923dc7-864c-47b0-a411-1f2c48d084de.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/79c6f036-bde6-4393-85a3-ef36a0327bd2.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2296,7 +2296,7 @@ Number of items: 6
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/dd3b289c-d90e-44a6-a44c-4880517eb1de.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/22870bbe-898f-4c17-a31a-d7c5ee5d1c10.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2352,7 +2352,7 @@ public class Client {
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/0889c0b4-07b4-45fc-873c-e0e16b97f67d.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ff5152fc-4ff3-44c4-95d6-1061002c364a.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2424,7 +2424,7 @@ public class Client {
|
|||
- Abstraction:定义抽象类的接口
|
||||
- Implementor:定义实现类接口
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c2cbf5d2-82af-4c78-bd43-495da5adf55f.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/2a1f8b0f-1dd7-4409-b177-a381c58066ad.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2582,7 +2582,7 @@ public class Client {
|
|||
|
||||
组合对象拥有一个或者多个组件对象,因此组合对象的操作可以委托给组件对象去处理,而组件对象可以是另一个组合对象或者叶子对象。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/77931a4b-72ba-4016-827d-84b9a6845a51.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/b25e75a5-7aa4-42f8-b2f8-d5f81c4fb2fc.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2714,7 +2714,7 @@ Composite:root
|
|||
|
||||
装饰者(Decorator)和具体组件(ConcreteComponent)都继承自组件(Component),具体组件的方法实现不需要依赖于其它对象,而装饰者组合了一个组件,这样它可以装饰其它装饰者或者具体组件。所谓装饰,就是把这个装饰者套在被装饰者之上,从而动态扩展被装饰者的功能。装饰者的方法有一部分是自己的,这属于它的功能,然后调用被装饰者的方法实现,从而也保留了被装饰者的功能。可以看到,具体组件应当是装饰层次的最低层,因为只有具体组件的方法实现不需要依赖于其它对象。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/137c593d-0a9e-47b8-a9e6-b71f540b82dd.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/6b833bc2-517a-4270-8a5e-0a5f6df8cd96.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2879,7 +2879,7 @@ public class Client {
|
|||
- IntrinsicState:内部状态,享元对象共享内部状态
|
||||
- ExtrinsicState:外部状态,每个享元对象的外部状态不同
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/d52270b4-9097-4667-9f18-f405fc661c99.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2968,7 +2968,7 @@ Java 利用缓存来加速大量小对象的访问时间。
|
|||
- 保护代理(Protection Proxy):按权限控制对象的访问,它负责检查调用者是否具有实现一个请求所必须的访问权限。
|
||||
- 智能代理(Smart Reference):取代了简单的指针,它在访问对象时执行一些附加操作:记录对象的引用次数;当第一次引用一个对象时,将它装入内存;在访问一个实际对象前,检查是否已经锁定了它,以确保其它对象不能改变它。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/a6c20f60-5eba-427d-9413-352ada4b40fe.png"/> </div><br>
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/9b679ff5-94c6-48a7-b9b7-2ea868e828ed.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
|
BIN
docs/pics/22870bbe-898f-4c17-a31a-d7c5ee5d1c10.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
docs/pics/2a1f8b0f-1dd7-4409-b177-a381c58066ad.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
docs/pics/2b125bcd-1b36-43be-9b78-d90b076be549.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/30d6e95c-2e3c-4d32-bf4f-68128a70bc05.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
docs/pics/40c0c17e-bba6-4493-9857-147c0044a018.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
docs/pics/50678f34-694f-45a4-91c6-34d985c83fee.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
docs/pics/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/pics/6b833bc2-517a-4270-8a5e-0a5f6df8cd96.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
docs/pics/79c6f036-bde6-4393-85a3-ef36a0327bd2.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
docs/pics/79df886f-fdc3-4020-a07f-c991bb58e0d8.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
docs/pics/89292ae1-5f13-44dc-b508-3f035e80bf89.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/pics/9b679ff5-94c6-48a7-b9b7-2ea868e828ed.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
docs/pics/a8c8f894-a712-447c-9906-5caef6a016e3.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
docs/pics/ac6a794b-68c0-486c-902f-8d988eee5766.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
docs/pics/b25e75a5-7aa4-42f8-b2f8-d5f81c4fb2fc.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
docs/pics/b8922f8c-95e6-4187-be85-572a509afb71.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/c44a0342-f405-4f17-b750-e27cf4aadde2.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/ca9f23bf-55a4-47b2-9534-a28e35397988.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/pics/cd1be8c2-755a-4a66-ad92-2e30f8f47922.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
docs/pics/db5e376d-0b3e-490e-a43a-3231914b6668.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
docs/pics/e2190c36-8b27-4690-bde5-9911020a1294.png
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
docs/pics/eca1f422-8381-409b-ad04-98ef39ae38ba.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
docs/pics/f4d0afd0-8e78-4914-9e60-4366eaf065b5.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
docs/pics/ff5152fc-4ff3-44c4-95d6-1061002c364a.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
notes/pics/22870bbe-898f-4c17-a31a-d7c5ee5d1c10.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
notes/pics/2a1f8b0f-1dd7-4409-b177-a381c58066ad.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
notes/pics/2b125bcd-1b36-43be-9b78-d90b076be549.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
notes/pics/30d6e95c-2e3c-4d32-bf4f-68128a70bc05.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
notes/pics/40c0c17e-bba6-4493-9857-147c0044a018.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
notes/pics/50678f34-694f-45a4-91c6-34d985c83fee.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
notes/pics/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
notes/pics/6b833bc2-517a-4270-8a5e-0a5f6df8cd96.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
notes/pics/79c6f036-bde6-4393-85a3-ef36a0327bd2.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
notes/pics/79df886f-fdc3-4020-a07f-c991bb58e0d8.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
notes/pics/89292ae1-5f13-44dc-b508-3f035e80bf89.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
notes/pics/9b679ff5-94c6-48a7-b9b7-2ea868e828ed.png
Normal file
After Width: | Height: | Size: 26 KiB |
BIN
notes/pics/a8c8f894-a712-447c-9906-5caef6a016e3.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
notes/pics/ac6a794b-68c0-486c-902f-8d988eee5766.png
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
notes/pics/b25e75a5-7aa4-42f8-b2f8-d5f81c4fb2fc.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
notes/pics/b8922f8c-95e6-4187-be85-572a509afb71.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
notes/pics/c44a0342-f405-4f17-b750-e27cf4aadde2.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
notes/pics/ca9f23bf-55a4-47b2-9534-a28e35397988.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
notes/pics/cd1be8c2-755a-4a66-ad92-2e30f8f47922.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
notes/pics/db5e376d-0b3e-490e-a43a-3231914b6668.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
notes/pics/e2190c36-8b27-4690-bde5-9911020a1294.png
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
notes/pics/eca1f422-8381-409b-ad04-98ef39ae38ba.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
notes/pics/f4d0afd0-8e78-4914-9e60-4366eaf065b5.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
notes/pics/ff5152fc-4ff3-44c4-95d6-1061002c364a.png
Normal file
After Width: | Height: | Size: 22 KiB |
|
@ -54,7 +54,7 @@
|
|||
|
||||
私有构造函数保证了不能通过构造函数来创建对象实例,只能通过公有静态函数返回唯一的私有静态变量。
|
||||
|
||||
<div align="center"> <img src="pics/562f2844-d77c-40e0-887a-28a7128abd42.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/eca1f422-8381-409b-ad04-98ef39ae38ba.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -255,7 +255,7 @@ secondName
|
|||
|
||||
这样做能把客户类和具体子类的实现解耦,客户类不再需要知道有哪些子类以及应当实例化哪个子类。客户类往往有多个,如果不使用简单工厂,那么所有的客户类都要知道所有子类的细节。而且一旦子类发生改变,例如增加子类,那么所有的客户类都要进行修改。
|
||||
|
||||
<div align="center"> <img src="pics/c79da808-0f28-4a36-bc04-33ccc5b83c13.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/40c0c17e-bba6-4493-9857-147c0044a018.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -338,7 +338,7 @@ public class Client {
|
|||
|
||||
下图中,Factory 有一个 doSomething() 方法,这个方法需要用到一个产品对象,这个产品对象由 factoryMethod() 方法创建。该方法是抽象的,需要由子类去实现。
|
||||
|
||||
<div align="center"> <img src="pics/1818e141-8700-4026-99f7-900a545875f5.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/f4d0afd0-8e78-4914-9e60-4366eaf065b5.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -402,7 +402,7 @@ public class ConcreteFactory2 extends Factory {
|
|||
|
||||
从高层次来看,抽象工厂使用了组合,即 Cilent 组合了 AbstractFactory,而工厂方法模式使用了继承。
|
||||
|
||||
<div align="center"> <img src="pics/8668a3e1-c9c7-4fcb-98b2-a96a5d841579.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/e2190c36-8b27-4690-bde5-9911020a1294.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -492,7 +492,7 @@ public class Client {
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/13b0940e-d1d7-4b17-af4f-b70cb0a75e08.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/db5e376d-0b3e-490e-a43a-3231914b6668.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -582,7 +582,7 @@ abcdefghijklmnopqrstuvwxyz
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/a40661e4-1a71-46d2-a158-ff36f7fc3331.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/b8922f8c-95e6-4187-be85-572a509afb71.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -643,7 +643,7 @@ abc
|
|||
|
||||
- Handler:定义处理请求的接口,并且实现后继链(successor)
|
||||
|
||||
<div align="center"> <img src="pics/691f11eb-31a7-46be-9de1-61f433c4b3c7.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/ca9f23bf-55a4-47b2-9534-a28e35397988.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -781,7 +781,7 @@ request2 is handle by ConcreteHandler2
|
|||
- Invoker:通过它来调用命令
|
||||
- Client:可以设置命令与命令的接收者
|
||||
|
||||
<div align="center"> <img src="pics/ae1b27b8-bc13-42e7-ac12-a2242e125499.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/c44a0342-f405-4f17-b750-e27cf4aadde2.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -902,7 +902,7 @@ public class Client {
|
|||
- TerminalExpression:终结符表达式,每个终结符都需要一个 TerminalExpression。
|
||||
- Context:上下文,包含解释器之外的一些全局信息。
|
||||
|
||||
<div align="center"> <img src="pics/794239e3-4baf-4aad-92df-f02f59b2a6fe.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/2b125bcd-1b36-43be-9b78-d90b076be549.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ false
|
|||
- Iterator 主要定义了 hasNext() 和 next() 方法。
|
||||
- Client 组合了 Aggregate,为了迭代遍历 Aggregate,也需要组合 Iterator。
|
||||
|
||||
<div align="center"> <img src="pics/b0f61ac2-a4b6-4042-9cf0-ccf4238c1ff7.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/89292ae1-5f13-44dc-b508-3f035e80bf89.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1116,7 +1116,7 @@ public class Client {
|
|||
- Mediator:中介者,定义一个接口用于与各同事(Colleague)对象通信。
|
||||
- Colleague:同事,相关对象
|
||||
|
||||
<div align="center"> <img src="pics/d0afdd23-c9a5-4d1c-9b3d-404bff3bd0d1.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/30d6e95c-2e3c-4d32-bf4f-68128a70bc05.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1286,7 +1286,7 @@ doSprinkler()
|
|||
- Caretaker:负责保存好备忘录
|
||||
- Menento:备忘录,存储原始对象的的状态。备忘录实际上有两个接口,一个是提供给 Caretaker 的窄接口:它只能将备忘录传递给其它对象;一个是提供给 Originator 的宽接口,允许它访问到先前状态所需的所有数据。理想情况是只允许 Originator 访问本备忘录的内部状态。
|
||||
|
||||
<div align="center"> <img src="pics/867e93eb-3161-4f39-b2d2-c0cd3788e194.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/50678f34-694f-45a4-91c6-34d985c83fee.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1467,7 +1467,7 @@ public class Client {
|
|||
|
||||
观察者(Observer)的注册功能需要调用主题的 registerObserver() 方法。
|
||||
|
||||
<div align="center"> <img src="pics/0df5d84c-e7ca-4e3a-a688-bb8e68894467.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/a8c8f894-a712-447c-9906-5caef6a016e3.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1594,7 +1594,7 @@ StatisticsDisplay.update: 1.0 1.0 1.0
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/c5085437-54df-4304-b62d-44b961711ba7.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/79df886f-fdc3-4020-a07f-c991bb58e0d8.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ No gumball dispensed
|
|||
- Strategy 接口定义了一个算法族,它们都实现了 behavior() 方法。
|
||||
- Context 是使用到该算法族的类,其中的 doSomething() 方法会调用 behavior(),setStrategy(Strategy) 方法可以动态地改变 strategy 对象,也就是说能动态地改变 Context 所使用的算法。
|
||||
|
||||
<div align="center"> <img src="pics/1fc969e4-0e7c-441b-b53c-01950d2f2be5.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/cd1be8c2-755a-4a66-ad92-2e30f8f47922.png"/> </div><br>
|
||||
|
||||
### 与状态模式的比较
|
||||
|
||||
|
@ -1988,7 +1988,7 @@ quack!
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/c3c1c0e8-3a78-4426-961f-b46dd0879dd8.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/ac6a794b-68c0-486c-902f-8d988eee5766.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2091,7 +2091,7 @@ Tea.addCondiments
|
|||
- ConcreteVisitor:具体访问者,存储遍历过程中的累计结果
|
||||
- ObjectStructure:对象结构,可以是组合结构,或者是一个集合。
|
||||
|
||||
<div align="center"> <img src="pics/ec923dc7-864c-47b0-a411-1f2c48d084de.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/79c6f036-bde6-4393-85a3-ef36a0327bd2.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2296,7 +2296,7 @@ Number of items: 6
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/dd3b289c-d90e-44a6-a44c-4880517eb1de.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/22870bbe-898f-4c17-a31a-d7c5ee5d1c10.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2352,7 +2352,7 @@ public class Client {
|
|||
|
||||
### Class Diagram
|
||||
|
||||
<div align="center"> <img src="pics/0889c0b4-07b4-45fc-873c-e0e16b97f67d.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/ff5152fc-4ff3-44c4-95d6-1061002c364a.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2424,7 +2424,7 @@ public class Client {
|
|||
- Abstraction:定义抽象类的接口
|
||||
- Implementor:定义实现类接口
|
||||
|
||||
<div align="center"> <img src="pics/c2cbf5d2-82af-4c78-bd43-495da5adf55f.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/2a1f8b0f-1dd7-4409-b177-a381c58066ad.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2582,7 +2582,7 @@ public class Client {
|
|||
|
||||
组合对象拥有一个或者多个组件对象,因此组合对象的操作可以委托给组件对象去处理,而组件对象可以是另一个组合对象或者叶子对象。
|
||||
|
||||
<div align="center"> <img src="pics/77931a4b-72ba-4016-827d-84b9a6845a51.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/b25e75a5-7aa4-42f8-b2f8-d5f81c4fb2fc.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2714,7 +2714,7 @@ Composite:root
|
|||
|
||||
装饰者(Decorator)和具体组件(ConcreteComponent)都继承自组件(Component),具体组件的方法实现不需要依赖于其它对象,而装饰者组合了一个组件,这样它可以装饰其它装饰者或者具体组件。所谓装饰,就是把这个装饰者套在被装饰者之上,从而动态扩展被装饰者的功能。装饰者的方法有一部分是自己的,这属于它的功能,然后调用被装饰者的方法实现,从而也保留了被装饰者的功能。可以看到,具体组件应当是装饰层次的最低层,因为只有具体组件的方法实现不需要依赖于其它对象。
|
||||
|
||||
<div align="center"> <img src="pics/137c593d-0a9e-47b8-a9e6-b71f540b82dd.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/6b833bc2-517a-4270-8a5e-0a5f6df8cd96.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2879,7 +2879,7 @@ public class Client {
|
|||
- IntrinsicState:内部状态,享元对象共享内部状态
|
||||
- ExtrinsicState:外部状态,每个享元对象的外部状态不同
|
||||
|
||||
<div align="center"> <img src="pics/d52270b4-9097-4667-9f18-f405fc661c99.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/5f5c22d5-9c0e-49e1-b5b0-6cc7032724d4.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
@ -2968,7 +2968,7 @@ Java 利用缓存来加速大量小对象的访问时间。
|
|||
- 保护代理(Protection Proxy):按权限控制对象的访问,它负责检查调用者是否具有实现一个请求所必须的访问权限。
|
||||
- 智能代理(Smart Reference):取代了简单的指针,它在访问对象时执行一些附加操作:记录对象的引用次数;当第一次引用一个对象时,将它装入内存;在访问一个实际对象前,检查是否已经锁定了它,以确保其它对象不能改变它。
|
||||
|
||||
<div align="center"> <img src="pics/a6c20f60-5eba-427d-9413-352ada4b40fe.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/9b679ff5-94c6-48a7-b9b7-2ea868e828ed.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
|
||||
|
|