Skip to content

Commit 0339c07

Browse files
committed
门面模式
1 parent e48a17c commit 0339c07

File tree

14 files changed

+255
-0
lines changed

14 files changed

+255
-0
lines changed

17-facade/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### 门面模式
2+
3+
#### 二个角色:
4+
5+
- Facade 门面角色
6+
7+
客户端可以调用这个角色的方法。此角色知晓子系统的所有功能和责任。
8+
一般情况下,本角色会将所有从客户端发来的请求委派到相应的子系统去,也就说
9+
该角色没有实际的业务逻辑,只是一个委托类。
10+
- Subsystem 子系统角色
11+
12+
可以同时有一个或多个子系统。每一个子系统都不是一个单独的类,而是一个类的
13+
集合。子系统并不知道门面的存在。对于子系统而言,门面仅仅是另外一个客户
14+
端而已。

17-facade/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>java-design-patterns</artifactId>
7+
<groupId>com.jiuxian</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<groupId>com.jiuxian</groupId>
13+
<artifactId>17-facade</artifactId>
14+
</project>
115 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jiuxian.definition;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 10:59:41
9+
* *
10+
* @description: 子系统A
11+
**/
12+
public class ClassA {
13+
14+
public void doSth() {
15+
System.out.println("子系统A 业务逻辑。。");
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jiuxian.definition;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 10:59:41
9+
* *
10+
* @description: 子系统B
11+
**/
12+
public class ClassB {
13+
14+
public void doSth() {
15+
System.out.println("子系统B 业务逻辑。。");
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jiuxian.definition;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 10:59:41
9+
* *
10+
* @description: 子系统C
11+
**/
12+
public class ClassC {
13+
14+
public void doSth() {
15+
System.out.println("子系统C 业务逻辑。。");
16+
}
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.jiuxian.definition;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 11:00:46
9+
* *
10+
* @description: 门面对象
11+
**/
12+
public class Facade {
13+
14+
private ClassA a = new ClassA();
15+
private ClassB b = new ClassB();
16+
private ClassC c = new ClassC();
17+
18+
public void methodA() {
19+
a.doSth();
20+
}
21+
22+
public void methodB() {
23+
b.doSth();
24+
}
25+
26+
public void methodC() {
27+
c.doSth();
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.jiuxian.definition;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 11:02:24
9+
* *
10+
* @description: 场景类
11+
**/
12+
public class Main {
13+
14+
public static void main(String[] args) {
15+
Facade facade = new Facade();
16+
17+
facade.methodA();
18+
facade.methodB();
19+
facade.methodC();
20+
}
21+
}
113 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.jiuxian.example;
2+
3+
/**
4+
* @author: liuzejun
5+
* *
6+
* @email: 857591294@qq.com
7+
* *
8+
* @date: 2019-05-30 11:23:24
9+
* *
10+
* @description: 写信过程接口
11+
**/
12+
public interface ILetterProcess {
13+
14+
void writeContext(String context);
15+
16+
void fillEnvelope(String address);
17+
18+
void letterIntoEnvelope();
19+
20+
void sendLetter();
21+
}

0 commit comments

Comments
 (0)