-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathBridgeClient.java
More file actions
29 lines (24 loc) · 699 Bytes
/
BridgeClient.java
File metadata and controls
29 lines (24 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package designpattern.bridge;
/**
* 客户端
*
* @author liu yuning
*
*/
public class BridgeClient {
public static void main(String[] args) {
Abstraction a = new AbstractionA("A");
a.setImplementor(new ConcreteImplemtorA());
a.operation();
a.setImplementor(new ConcreteImplemtorB());
a.operation();
Abstraction b = new AbstractionB("B");
b.setImplementor(new ConcreteImplemtorA());
b.operation();
b.setImplementor(new ConcreteImplemtorB());
b.operation();
// 这样通过使用“组合/聚合复用原则”
// 如果继续有AbstractionC ... 或者ConcreteImplemtorC ...
// 只需要扩展类即可,不需要修改现有类,符合“开放-封闭”原则
}
}