Proxy模式(動態代理)
這是JDK自帶的Proxy模式的實現方法
例子
view plaincopy to clipboardprint?
public interface GirlInfo {
public void hasBoyFriend();
}
public class Girl implements GirlInfo {
public void hasBoyFriend() {
System
}
}
public class GirlProxy implements InvocationHandler {
private Object delegate;
public Object bind(Object delegate) {
this
return Proxy
delegate
}
public Object invoke(Object proxy
throws Throwable {
method
return null;
}
}
public class ProxyClient {
public static void main(String[] args) {
GirlProxy girlProxy = new GirlProxy();
GirlInfo girl = (GirlInfo) girlProxy
girl
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25861.html