大话设计模式-***模式
/**
* 定义一个统一的接口
* 里面包含了真实用户和***都要实现的方法
*/
public interface Subject {
void Request();
}
/**
* 真实的用户
*/
public class RealSubject implements Subject {
@Override
public void Request() {
System.out.println("真实的请求");
}
}
/**
* ***用户发起请求
*/
public class Proxy implements Subject {
//真实用户
private RealSubject realSubject;
public Proxy() {
if (realSubject == null) {
realSubject = new RealSubject();
}
}
public Proxy(RealSubject realSubject) {
this.realSubject = realSubject;
}
@Override
public void Request() {
realSubject.Request();
}
}
public class Main {
public static void main(String[] args) {
Proxy proxy = new Proxy();
proxy.Request();
}
}