0
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| // 子系统接口
public interface SubsystemA {
void operationA();
}
public interface SubsystemB {
void operationB();
}
public interface SubsystemC {
void operationC();
}
// 具体子系统实现
public class ConcreteSubsystemA implements SubsystemA {
@Override
public void operationA() {
System.out.println("SubsystemA operation A");
}
}
public class ConcreteSubsystemB implements SubsystemB {
@Override
public void operationB() {
System.out.println("SubsystemB operation B");
}
}
public class ConcreteSubsystemC implements SubsystemC {
@Override
public void operationC() {
System.out.println("SubsystemC operation C");
}
}
// 外观类
public class Facade {
private SubsystemA subsystemA;
private SubsystemB subsystemB;
private SubsystemC subsystemC;
public Facade() {
subsystemA = new ConcreteSubsystemA();
subsystemB = new ConcreteSubsystemB();
subsystemC = new ConcreteSubsystemC();
}
public void operation() {
subsystemA.operationA();
subsystemB.operationB();
subsystemC.operationC();
}
}
// 客户端代码
public class Client {
public static void main(String[] args) {
Facade facade = new Facade();
facade.operation();
}
}
|