-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS12_Proxy.java
More file actions
45 lines (33 loc) · 825 Bytes
/
DS12_Proxy.java
File metadata and controls
45 lines (33 loc) · 825 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
30
31
32
33
34
35
36
37
38
39
40
41
//Proxy
class ProxyObject implements Object {
Object obj;
public ProxyObject() {
System.out.println("这是代理类");
obj = new ObjectImpl();
}
public void action() {
System.out.println("代理开始");
obj.action();
System.out.println("代理结束");
}
}
//Subject
interface Object {
void action();
}
//RealSubject
class ObjectImpl implements Object {
public void action() {
System.out.println("========");
System.out.println("========");
System.out.println("这是被代理的类");
System.out.println("========");
System.out.println("========");
}
}
public class DS12_Proxy{
public static void main(String[] args){
Object obj = new ProxyObject();
obj.action();
}
}