public interface Sourceable {
void method();
}
public class Source implements Sourceable{
@Override
public void method() {
System.out.println("Source method");
}
}
public class Proxy implements Sourceable {
private Source source;
public Proxy() {
this.source = new Source();
}
@Override
public void method() {
before();
source.method();
atfer();
}
private void before() {
System.out.println("Proxy before");
}
private void atfer() {
System.out.println("Proxy atfer");
}
}
public class Test {
public static void main(String[] args) {
try {
Test test = new Test();
} catch (Exception e) {
e.printStackTrace();
}
}
public Test() {
Sourceable source = new Proxy();
source.method();
}
}
输出:
Proxy before
Source method
Proxy atfer