Skip to content

Commit d469e7e

Browse files
committed
静态代理
1 parent f2d5ac6 commit d469e7e

8 files changed

Lines changed: 97 additions & 1 deletion

File tree

.idea/libraries/Maven__cglib_cglib_nodep_2_2.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pattern/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@
8484
## [代理模式](src/main/java/com/cpucode/pattern/proxy)
8585

8686
- [x] [静态代理__StaticProxyTest](src/main/java/com/cpucode/pattern/proxy/staticproxy/StaticProxyTest.java)
87+
- [x] [静态代理__Client](src/main/java/com/cpucode/pattern/proxy/simpleproxy/Client.java)
8788
- [x] [静态代理__DbRouteProxyTest](src/main/java/com/cpucode/pattern/proxy/db/route/proxy/staticdb/DbRouteProxyTest.java)
8889
- [x] [动态代理__DbRouteProxyTest](src/main/java/com/cpucode/pattern/proxy/db/route/proxy/dynamic/DbRouteProxyTest.java)
8990
- [x] [JDK动态代理__JDKProxyTest](src/main/java/com/cpucode/pattern/proxy/dynamicproxy/jdkproxy/JDKProxyTest.java)
9091
- [x] [JDK手写实现__GPProxyTest](src/main/java/com/cpucode/pattern/proxy/dynamicproxy/gpproxy/GPProxyTest.java)
91-
92+
9293

9394
## [适配器模式]()
9495

pattern/pattern.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
</content>
1212
<orderEntry type="inheritedJdk" />
1313
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.2" level="project" />
1415
</component>
1516
</module>

pattern/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
<artifactId>pattern</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

11+
<dependencies>
12+
<dependency>
13+
<groupId>cglib</groupId>
14+
<artifactId>cglib-nodep</artifactId>
15+
<version>2.2</version>
16+
</dependency>
17+
</dependencies>
18+
1119
<build>
1220
<plugins>
1321
<!-- java编译插件 -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.cpucode.pattern.proxy.simpleproxy;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/5/30
6+
* @time : 17:50
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class Client {
11+
public static void main(String[] args) {
12+
Proxy proxy = new Proxy(new RealSubject());
13+
proxy.request();
14+
}
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.cpucode.pattern.proxy.simpleproxy;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/5/30
6+
* @time : 17:49
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class Proxy implements Subject {
11+
private Subject subject;
12+
13+
public Proxy(Subject subject){
14+
this.subject = subject;
15+
}
16+
17+
@Override
18+
public void request() {
19+
before();
20+
subject.request();
21+
after();
22+
}
23+
24+
public void before(){
25+
System.out.println("called before request().");
26+
}
27+
28+
public void after(){
29+
System.out.println("called after request().");
30+
}
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.cpucode.pattern.proxy.simpleproxy;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/5/30
6+
* @time : 17:49
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public class RealSubject implements Subject{
11+
@Override
12+
public void request() {
13+
System.out.println("real service is called.");
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.cpucode.pattern.proxy.simpleproxy;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/5/30
6+
* @time : 17:45
7+
* @github : https://github.com/CPU-Code
8+
* @csdn : https://blog.csdn.net/qq_44226094
9+
*/
10+
public interface Subject {
11+
void request();
12+
}

0 commit comments

Comments
 (0)