代理类相当于古代的摄政王!
//接口
public interface Subject { void request(); }
// 被代理的类
public class RealSubject implements Subject{ @Override public void request() { System.out.println("RealSubject request"); } }
// 代理类
public class Proxy implements Subject{ private RealSubject realSubject; public Proxy(RealSubject realSubject) { this.realSubject = realSubject; } @Override public void request() { // 预处理 preRequest(); // 调用真实主题 realSubject.request(); // 后处理 postRequest(); } private void preRequest() { System.out.println("Proxy preRequest"); } private void postRequest() { System.out.println("Proxy postRequest"); } }
标签:什么,request,代理,public,Proxy,realSubject,void From: https://www.cnblogs.com/easycoding20211115/p/17656374.html