Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 96fa0e3

Browse files
author
deeper
committed
static proxy
1 parent d3693e4 commit 96fa0e3

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.ruoxu.pattern.proxy.dynamic_proxy;
2+
3+
/**
4+
* 动态代理
5+
*
6+
*
7+
*/
8+
public class Demo {
9+
public static void main(String[] args) {
10+
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.ruoxu.pattern.proxy.static_proxy;
2+
3+
/**
4+
* 静态代理
5+
*
6+
*
7+
*/
8+
public class Demo {
9+
public static void main(String[] args) {
10+
ILawsuit poorMan = new PoorMan();
11+
LawyerProxy lawyerProxy = new LawyerProxy(poorMan);
12+
lawyerProxy.submit();
13+
lawyerProxy.burden();
14+
lawyerProxy.defend();
15+
lawyerProxy.finish();
16+
17+
System.out.println();
18+
19+
ILawsuit wealthMan = new WealthMan();
20+
LawyerProxy proxy = new LawyerProxy(wealthMan);
21+
proxy.submit();
22+
proxy.burden();
23+
proxy.defend();
24+
proxy.finish();
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.ruoxu.pattern.proxy.static_proxy;
2+
/**
3+
* 诉讼接口类
4+
*
5+
*/
6+
public interface ILawsuit {
7+
// 提交申请
8+
void submit();
9+
// 进行举证
10+
void burden();
11+
// 开始辩护
12+
void defend();
13+
// 诉讼完成
14+
void finish();
15+
16+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.ruoxu.pattern.proxy.static_proxy;
2+
3+
/**
4+
* 律师(代理人)
5+
* 代理模式不仅可以代理一个对象,也可以代理多个对象
6+
*
7+
*/
8+
public class LawyerProxy implements ILawsuit{
9+
10+
private ILawsuit mILaysuit ;
11+
12+
/**
13+
* 代理一个对象
14+
* @param iLawsuit
15+
*/
16+
public LawyerProxy(ILawsuit iLawsuit) {
17+
this.mILaysuit = iLawsuit;
18+
}
19+
20+
/**
21+
* 根据个人资产 代理多个对象
22+
* @param totalMoney
23+
*
24+
public LawyerProxy(int totalMoney) {// 代理模式不仅可以代理一个对象,也可以代理多个对象
25+
if(totalMoney > 10000){
26+
mILaysuit = new PoorMan();
27+
}else{
28+
mILaysuit = new WealthMan();
29+
}
30+
}
31+
*/
32+
33+
@Override
34+
public void submit() {
35+
System.out.print("【proxy===");
36+
mILaysuit.submit();
37+
System.out.println("===】");
38+
}
39+
40+
@Override
41+
public void burden() {
42+
System.out.print("【proxy===");
43+
mILaysuit.burden();
44+
System.out.println("===】");
45+
}
46+
47+
@Override
48+
public void defend() {
49+
System.out.print("【proxy===");
50+
mILaysuit.defend();
51+
System.out.println("===】");
52+
}
53+
54+
@Override
55+
public void finish() {
56+
System.out.print("【proxy===");
57+
mILaysuit.finish();
58+
System.out.println("===】");
59+
}
60+
61+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ruoxu.pattern.proxy.static_proxy;
2+
3+
public class PoorMan implements ILawsuit{
4+
private static final String PREFIX = "poorMan ";
5+
6+
@Override
7+
public void submit() {
8+
System.out.print(PREFIX+"submit");
9+
}
10+
11+
@Override
12+
public void burden() {
13+
System.out.print(PREFIX+"burden");
14+
}
15+
16+
@Override
17+
public void defend() {
18+
System.out.print(PREFIX+"defend");
19+
}
20+
21+
@Override
22+
public void finish() {
23+
System.out.print(PREFIX+"finish");
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ruoxu.pattern.proxy.static_proxy;
2+
3+
public class WealthMan implements ILawsuit{
4+
private static final String PREFIX = "wealthMan ";
5+
6+
@Override
7+
public void submit() {
8+
System.out.print(PREFIX+"submit");
9+
}
10+
11+
@Override
12+
public void burden() {
13+
System.out.print(PREFIX+"burden");
14+
}
15+
16+
@Override
17+
public void defend() {
18+
System.out.print(PREFIX+"defend");
19+
}
20+
21+
@Override
22+
public void finish() {
23+
System.out.print(PREFIX+"finish");
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /