In some situations it could be necessary to create proxies programmatically (for example in test classes), in the classic manner or with classes annotated with "@Aspect
".
To see a proxy in action, we will use as example class a class that implements a Command Pattern. A Command Pattern is used when a client class doesn't know the details about an implementation of the called class that executes some logic.
package org.springaop.chapter.three.proxy; public interface Command { public void execute(); }
We define an interface that implements the Command Pattern (http://en.wikipedia.org/wiki/Command_pattern).
package org.springaop.chapter.three.proxy; public class CommandImpl implements Command{ public void execute(){ System.out.println(label); } private final String label = "Goooo !"; }
We create a class that implements the interface.
package org.springaop.chapter.three.proxy; public class BeforeAdviceProxyExample implements MethodBeforeAdvice{ public...