What is the important idea behind the Java – AOP implementation?
I want to make it clear to me
I read the concept of AOP and I understand that it is a good way to share cross domain services (records, security, transactions...)
But I want to say / ask about this idea and its implementation
I read that there are some methods, such as AspectJ, JBoss and AOP, to assimilate AOP into my business logic
But wasn't it here a long time ago?
For example, I want to share a logging or security implementation between my components (Java beans, EJBs', anyway...)
Why can't I let the singleton bean ensure that it has only one instance? As long as any component needs its log / security service, it will find and use its service
Why do I need to know and have all those "big" implementations, such as AspectJ or JBoss AOP? What do I miss here?
Solution
The idea of AOP is to keep the common logic in one place (your single solution also solves this problem) and be "invisible" (transparent) With AOP, your logging code is not even part of business logic, it will be "injected" in the background
In addition, it is more dynamic - you do not need to call the singleton service every time you need to record You only need to configure the pointcut once (for example: "all setters in this package") and apply logging to all existing and new code
In addition, AOP is more flexible and powerful You can ask the AOP implementation: "every time a method starting with" save * "is called, a transaction must be started. If the returned method returns an exception subclass thrown by the customer from the illegalagementexception, take a parameter" or "and call the method again"
AOP is more than just grouping common logic