forked from shijiebei2009/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaticProxyHandler.java
59 lines (50 loc) · 1.41 KB
/
StaticProxyHandler.java
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
package cn.codepub.patterns.proxy;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/21 19:33
* </p>
* <p>
* ClassName:CountProxy
* </p>
* <p>
* Description:静态代理的实现
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class StaticProxyHandler implements Count {
private Count count;
//默认构造器
public StaticProxyHandler() {
}
//接收被代理类实例的构造器
public StaticProxyHandler(Count count) {
this.count = count;
}
@Override
public void queryCount() {
System.out.println("before method invoke...");
//调用委托类的方法
count.queryCount();
System.out.println("after method invoke...");
}
@Override
public void updateCount() {
System.out.println("before method invoke...");
//调用委托类的方法
count.updateCount();
System.out.println("after method invoke...");
}
public static void main(String[] args) {
testStaticProxy();
}
public static void testStaticProxy() {
System.out.println("-----------使用静态代理-----------");
CountImpl countImpl = new CountImpl();
StaticProxyHandler staticProxyHandler = new StaticProxyHandler(countImpl);
staticProxyHandler.queryCount();
staticProxyHandler.updateCount();
}
}