3 ms·
A more practical explanation of stuff you can do with AOP that would be challenging otherwise: https://debugagent.com/spring-boot-debugging-with-aspect-oriented
by invalidname 3y ago
A more practical explanation of stuff you can do with AOP that would be challenging otherwise: https://debugagent.com/spring-boot-debugging-with-aspect-oriented-programming-aop https://debugagent.com/spring-boot-debugging-with-aspect-ori...
- unscaled 3y agoLooking at what AOP is still used for nowadays, it's pretty clear that the killer application for AOP was always logging (and nowadays that would also include tracing). There were many other suggested use cases of course: transactions, caching, application-level security, dependency injection, retries, refactoring a legacy app... The problem with all of the other suggested use cases is that AOP was never a great fit for them. AOP is always casting a wide net, which has the following two properties: 1. False positives: It's very easy to wrap all methods in the com.myapp.* package which fit the pattern "interact*()" with some transaction manager, or to cache their result. But a few years later a hapless developer adds another "interact" method which suddenly starts to misbehave. Logging has very little impact on behavior, but most of the other use cases (even caching and retries) can greatly impact behavior, so you'd usually want more control on them. Of course, you could define a very narrow pointcut which doesn't risk a false positive — but in that case, why shouldn't you just use an annotation? 2. Large amount of join points: AOP works great to save you writing a lot of boilerplate code when you need to modify a large number of functions in a similar way. In modern programming languages you'd often use annotations (which postdate AOP, especially within Java), but even adding a single annotation on thousands of methods is tedious and error-prone. But again, out of all these use-cases, only logging really often needs to do the exact same thing for thousands of methods. Caching, Retries and Dependency Injection require more in-site knowledge that is easier to achieve and more readable with annotations: which values you want to cache, what dependencies to inject and what would be their life time and source, which retry strategy should you use, etc.