proxy代理模式 多一个代理类出来 替原对象完成一些功能
public class Proxy implements Sourceable {
private Source source;
public Proxy() {
super();
this.source = new Source();
}
@Override
public void method() {
before();
source.method();
after();
}
private void after() {
System.out.println("this is after method");
}
private void before() {
System.out.println("this is before method");
}
}
interface Sourceable {
void method();
}
class Source implements Sourceable {
@Override
public void method() {
System.out.println("this is original method");
}
}
class Test{
public static void main(String[]args){
Sourceable sourceable= new Proxy();
sourceable.method();
}
}
得到的输出结果为: