auto commit
This commit is contained in:
parent
7b91ea78f4
commit
44244bf63a
|
@ -1326,6 +1326,58 @@ public class Client {
|
|||
|
||||
## 5. 外观(Facade)
|
||||
|
||||
### 意图
|
||||
|
||||
提供了一个统一的接口,用来访问子系统中的一群接口,从而让子系统更容易使用。
|
||||
|
||||
### 类图
|
||||
|
||||
<div align="center"> <img src="../pics//f9978fa6-9f49-4a0f-8540-02d269ac448f.png"/> </div><br>
|
||||
|
||||
### 实现
|
||||
|
||||
```java
|
||||
public class SubSystem {
|
||||
public void turnOnTV() {
|
||||
System.out.println("turnOnTV()");
|
||||
}
|
||||
|
||||
public void setCD(String cd) {
|
||||
System.out.println("setCD( " + cd + " )");
|
||||
}
|
||||
|
||||
public void starWatching(){
|
||||
System.out.println("starWatching()");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
public class Facade {
|
||||
private SubSystem subSystem = new SubSystem();
|
||||
|
||||
|
||||
public void watchMovie() {
|
||||
subSystem.turnOnTV();
|
||||
subSystem.setCD("a movie");
|
||||
subSystem.starWatching();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
public class Client {
|
||||
public static void main(String[] args) {
|
||||
Facade facade = new Facade();
|
||||
facade.watchMovie();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 设计原则
|
||||
|
||||
最少知识原则:只和你的密友谈话。也就是客户对象所需要交互的对象应当尽可能少。
|
||||
|
||||
## 6. 享元(Flyweight)
|
||||
|
||||
### 意图
|
||||
|
|
BIN
pics/f9978fa6-9f49-4a0f-8540-02d269ac448f.png
Normal file
BIN
pics/f9978fa6-9f49-4a0f-8540-02d269ac448f.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
Loading…
Reference in New Issue
Block a user