
Aspect-Oriented Programming (AOP)
A typical JAVA application is developed with multiple layers, each layer having a different responsibility. But, in each of these layers, there are a few common aspects, that is, Logging, Security, Validation, Caching, etc. These common aspects are called cross-cutting concerns. Now, if we implement these cross-cutting concerns in each and every layer separately, the code becomes repetitive and difficult to maintain. Moreover, it does not make any sense to write a similar block of code in every layer. Here comes the concept of Aspect-Oriented Programming.
Aspect-Oriented Programming -
-
Implement the cross-cutting concerns as an aspect
-
Define pointcuts to indicate where the aspect has to be applied.
It ensures that the cross-cutting concerns are defined in one cohesive code component.
There are some important terms in Aspect-Oriented Programming -
-
Join Point - A point during the execution of a program/method.
-
Advice - Action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice.
-
Pointcut - A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut

.png)
The advice and pointcut in the above code are-
Advice - “@After”, @Before
Pointcut - "execution(public * getEventBookingById(String,..))" + "|| execution(public * getUserById(java.util.UUID,..))", "execution(public * getUserById(java.util.UUID,..))", etc.