AWS App Design - Aspects
Aspect programming (AOP) has fallen out of favor over the last several years but it's extremely useful for two crosscutting concerns - Security and Logging. Instead of security and logging calls scattered haphazardly throughout your code, they're grouped into one area and dynamically injected into unpolluted code. In this example, the aspect is injected before and after the validate() method executes:
Define a logging aspect:
public aspect LoggingAspect {
void around(): call(void Login.validate()) {
System.out.println("logging before...");
proceed();
System.out.println("logging after...");
}
}
Define the target join point:
public class Login {
public boolean validate(String password) {
return Security.validate(password);
}
}
The aspect will log a before and after statement when Login.validate() executes. Notice the Login class isn't polluted with log statements and the aspect can be enabled or disabled without changing the join point. The aspect can access internal variables within the join point but that's more complex and my goal is to show the concept of AOP.
The target classes have no knowledge or reference to security and logging code, which means it can be altered, enabled or disabled independent of the application code.