Skip to content

Commit 06ab7ab

Browse files
authored
代理模式
代理模式
1 parent bd69c2f commit 06ab7ab

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.java.design.proxy;
2+
3+
public interface Dog {
4+
5+
void eat();
6+
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.java.design.proxy;
2+
3+
public class DogImpl implements Dog {
4+
5+
@Override
6+
public void eat() {
7+
8+
System.out.println("Dog eating shit !");
9+
}
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.java.design.proxy;
2+
3+
public class DogProxy implements Dog {
4+
5+
Dog dog;
6+
7+
public DogProxy() {
8+
dog = new DogImpl();
9+
}
10+
11+
@Override
12+
public void eat() {
13+
System.out.println("静态代理开始 ...");
14+
dog.eat();
15+
System.out.println("静态代理结束 ...");
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.java.design.proxy;
2+
3+
/**
4+
* 代理模式 -----> 所谓代理模式是指客户端并不直接调用实际的对象,而是通过调用代理,来间接的调用实际的对象。
5+
*
6+
* @author Administrator
7+
*
8+
*/
9+
public class ProxyPattern {
10+
11+
public static void main(String[] args) {
12+
13+
// 这里示范的为静态代理模式
14+
Dog dog = new DogProxy();
15+
dog.eat();
16+
}
17+
18+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy