AOP
As an aspect-oriented programming paradigm, it extracts common logic so that it can be executed at various points of a method, reducing code and allowing developers to focus on core concerns while excluding common logic.
What is AOP?
A key principle of a good development environment is to
allow developers to focus only on business logicThere are several important principles for this goal, but the most easily conceivable one is
eliminating repetitive codeThe Spring Framework provides ways to reduce such repetitive code and focus only on core business logic
Common concerns shared by most systems, such as security, logging, and transactions, are not business logic but are essential processing. In Spring, these are called
cross-cutting concernsSpring allows these cross-cutting concerns to be developed separately
AOPis a programming paradigm thatseparates cross-cutting concerns into modules
In the AOP technique,
common functionalityis not directly called fromcode implementing core logicAOP is applied when
compilingthe code implementing core logic, whenloadingthe compiled class, or whencreating an objectof the loaded class, inserting common functionality into the core logic implementation codeEven if common functionality changes, the code implementing core logic does not need to be modified
Advantages of AOP
Developers can focus on developing only the core business logic,
When applying different concerns to each project, code modifications can be minimized,
Maintainability of desired concerns becomes easier with well-structured code
AOP Terminology
TargetA module containing core functionality; it becomes the
subject to which additional functionality is applied
AdviceDefines the
additional functionalityto provide to the targetTypes of Advice
AroundDefines additional functionality that needs to be processed at both the before and after points when the target method is called
Advice that executes before and after the Joinpoint
BeforeDefines additional functionality that needs to be processed before the target method executes
Advice that executes before the Joinpoint
After ReturningDefines additional functionality that needs to be processed after the target method executes normally
Advice that executes after the Joinpoint method call terminates normally
After ThrowingDefines additional functionality that needs to be processed after the target method throws an exception
Advice that executes when an exception is thrown
JoinPointA location where advice can be
appliedAll methods of the interface implemented by the target object become join points
PointcutA regular expression that
selects methodsof thetarget to which advice is appliedDetermines
where to applythe Advice!
Pointcut expressions start with
executionand primarily use the method of comparing methodsignatures
WeavingThe process of
insertingadditional functionality (advice) into thejoinpointof a target determined by the PointcutWeaving is a core processing step that allows AOP to
addnecessary additional functionality (advice) withoutaffectingthe code of thecore functionality (target)
AspectThe basic module of AOP
Aspect = Advice + PointcutAn Aspect exists as a singleton object
When applying the AOP concept, additional functionality embedded within core functionality code can be separated into
independent aspectsSeparated additional functionality aspects can dynamically participate at necessary locations at runtime
AdvisorAdvisor = Advice + Pointcut
Advisor is a special term used only in Spring AOP
Last updated