标签:技术 extends proxy ext 发放 code wan something 代理模式
abstract public class Subject { /** * 生命一个抽象的请求发放 */ abstract public void request(); }
public class RealSubject extends Subject{ /** * 构造子 */ public RealSubject(){} /** * 实现请求求方法 */ public void request() { System.out.println("From real subject"); } }
public class ProxySubject extends Subject{ private RealSubject realSubject; /** * 构造子 */ public ProxySubject(){} /** * 实现请求方法 */ public void request(){ preRequest(); if(realSubject == null){ realSubject = new RealSubject(); } realSubject.request(); postRequest(); } /** * 请求前的操作 */ private void preRequest(){ //something you want to do before requesting. } /** * 请求后的操作 */ private void postRequest(){ //something you want to do after requesting. } }
标签:技术 extends proxy ext 发放 code wan something 代理模式
原文地址:http://www.cnblogs.com/loytime/p/7716951.html