标签:
/** * @author liubo * */ public interface Sourceable { public void method(); }
package com.liubo.patterns.proxy; /** * @author liubo * */ public class Source implements Sourceable { public void method() { System.out.println("the original method"); } }
package com.liubo.patterns.proxy; /** * @author liubo * */ public class Proxy implements Sourceable { private Sourceable source; /** * @param source */ public Proxy(Sourceable source) { super(); this.source = source; } public void method() { before(); source.method(); after(); } public void before() { System.out.println("before proxy"); } public void after() { System.out.println("after proxy"); } }
package com.liubo.patterns.proxy; import org.junit.Test; /** * @author liubo * */ public class ProxyTest { @Test public void testProxy() { Sourceable source = new Source(); Sourceable sourceTest = new Proxy(source); sourceTest.method(); } }
标签:
原文地址:http://www.cnblogs.com/liubo6/p/4550892.html