23种设计模式之代理模式
代理模式:为其他对象提供一种代理以控制对这个对象的访问。
package designMode.proxy; interface Subject { void request(); }
package designMode.proxy; class RealSubject implements Subject{ @Override public void request() { System.out.println("真实的请求!"); } }
package designMode.proxy; class Proxy implements Subject{ RealSubject realSubject; @Override public void request() { if(realSubject==null) realSubject=new RealSubject(); realSubject.request(); } }
package designMode.proxy; class Test { public static void main(String[] args) { Proxy p = new Proxy(); p.request(); } }