24种设计模式-代理
代理模式,:实际工作的类被隐藏在代理类的后面。当你调用代理类中的方法,实际上调用的是实体类中的方法
package design; /** * Created by Administrator on 2018/4/19. */ public interface ProxyBase { void f(); void g(); void h(); }
package design; /** * Created by Administrator on 2018/4/19. */ public class Proxy implements ProxyBase { private ProxyBase impelmentation; public Proxy(){ impelmentation=new Implementation(); } public void f() { impelmentation.f(); } public void g() { impelmentation.g(); } public void h() { impelmentation.h(); } } class Implementation implements ProxyBase { public void f() { System.out.println("Implementation.f()"); } public void g() { System.out.println("Implementation.g()"); } public void h() { System.out.println("Implementation.h()"); } }
package design; /** * Created by Administrator on 2018/4/19. */ public class ProxyDemo { Proxy p = new Proxy(); public void test() { // This just makes sure it will complete // without throwing an exception. p.f(); p.g(); p.h(); } public static void main(String args[]) { junit.textui.TestRunner.run(ProxyDemo.class); } }