Proxy Proxy
Ce design pattern est utilisé intensément par Spring pour tout ce qui concerne la programmation orientée aspect (AOP) et les accès à distance.
L’AOP est décrit en détail dans le chapitre Programmation orientée aspect avec Spring.
Spring ne donne pas un accès direct aux objets mais via un objet intermédiaire appelé proxy ce qui permet à Spring de modifier le comportement de l’objet d’origine.
interface Pojo3 {
public void foo();
}
class SimplePojo3 implements Pojo3 {
public void foo() {
System.out.println("foo");
}
}
class RetryAdvice implements AfterReturningAdvice {
public void afterReturning(Object returnValue, Method method,
Object[] args, Object target) throws Throwable {
System.out.println("Après "+method.getName());
}
}
public class MainAvecAspect {
public static void main(String[] args) {
ProxyFactory factory = new ProxyFactory(new SimplePojo3());
Class<?> intf=Pojo3.class;
factory.addInterface(intf);
Advice advice=new...