forked from mirsfang/ExamplesOfDesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyMain.java
More file actions
52 lines (38 loc) · 1.07 KB
/
ProxyMain.java
File metadata and controls
52 lines (38 loc) · 1.07 KB
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
package structure.proxy;
import structure.proxy.dynamicProxy.RealSujectImpl;
import structure.proxy.dynamicProxy.Subject;
import structure.proxy.dynamicProxy.SubjectInvocationHandler;
import structure.proxy.staticProxy.Proxy;
import structure.proxy.staticProxy.RealSuject;
/***
*作者:MirsFang
*模式:代理模式
*时间:2017/2/28/
*备注 代理模式运行类
***/
public class ProxyMain {
public static void main(String[] args) {
// staticProxy();
dynamicProxy();
}
/*
* 静态代理
* */
private static void staticProxy() {
RealSuject realSuject = new RealSuject();
Proxy proxy = new Proxy(realSuject);
proxy.request();
}
/**
*
*作者:Mirsfang
*日期:2017/2/28/下午12:54
*描述:动态代理
**/
private static void dynamicProxy(){
RealSujectImpl realSubject=new RealSujectImpl();
SubjectInvocationHandler handler=new SubjectInvocationHandler(realSubject);
Subject subject= (Subject) handler.getProxy();
subject.request();
}
}