1.定义
为其他对象提供一种代理以控制对这个对象的访问。
2.UML
3.代码
public interface Subject {
void request();
}
public class RealSubject implements Subject {
@Override
public void request() {
}
}
public class Proxy implements Subject {
private Subject mSubject;
public Proxy() {
mSubject = new RealSubject();
}
@Override
public void request() {
before();
mSubject.request();
after();
}
private void before() {
}
private void after() {
}
}
public class Client {
public static void main(String[] args) {
Subject proxy = new Proxy();
proxy.request();
}
}