import org.aopalliance.aop.Advice;
public class LoggingAdvice implements Advice {
public void before() {
}
}
public interface UserService {
void addUser(User user);
}
public class UserServiceImpl implements UserService {
public void addUser(User user) {
}
}
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class LoggingInterceptor implements MethodInterceptor {
public LoggingInterceptor(LoggingAdvice advice) {
this.advice = advice;
}
public Object invoke(MethodInvocation invocation) throws Throwable {
return result;
}
}
public class Main {
public static void main(String[] args) {
LoggingAdvice advice = new LoggingAdvice();
UserService userService = new UserServiceImpl();
LoggingInterceptor interceptor = new LoggingInterceptor(advice);
UserService proxy = (UserService) ProxyFactory.createProxy(userService, interceptor);
User user = new User("Alice");
proxy.addUser(user);
}
}