在这里插入图片描述
代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
interface NetWork{
public void browse();
}
//被代理类
class Server implements NetWork{
public void browse(){
System.out.println("真实的服务器访问网络");
}
}
//代理类
class ProxyServer implements NetWork{
private NetWork work;

public ProxyServer(NetWork work){
this.work = work;
}
public void chek(){
System.out.println("联网之前的检查工作");
}
public void browse(){
chec();
work.browse();
}
}
1
2
3
4
5
6
7
public class ProxyTest {
public static void main(String[] args) {
Server server = new Server();
ProxyServer pro = new ProxyServer(server);
pro.browse();
}
}

运行结果
在这里插入图片描述