一、编程方式使用切面
public class Test {
interface IA{
void f();
}
static class A2 implements IA{
@Override
public void f() {
System.out.println("i am f");
}
}
public static void main(String[] args) {
ProxyFactory proxyFactory = new ProxyFactory(new A2());
proxyFactory.addAdvice(new MethodBeforeAdvice() {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
System.out.println("before");
}
});
IA proxy =(IA) proxyFactory.getProxy();
proxy.f();
}
}
这里已经出现了Advice概念,我们以这个为切入点进行