- 主题抽象类或接口
public interface ISubject {
void doSomething();
void doAnything();
}
- 主题抽象类或接口实际类
public class RealSubject implements ISubject{
@Override
public void doSomething() {
//具体逻辑
}
@Override
public void doAnything() {
//具体逻辑
}
}
- 主题抽象类或接口代理类
public class ProxySubject implements ISubject {
ISubject realSubject = null;
public ProxySubject(ISubject subject) {
this.realSubject = subject;
}
@Override
public void doSomething() {
this.realSubject.doSomething();
}
@Override
public void doAnything() {
this.realSubject.doAnything();
}
}
- 使用
ISubject realSubject = new RealSubject();
ISubject proxySubject = new ProxySubject(realSubject);
proxySubject.doSomething();
proxySubject.doAnything();