Aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to the existing code (an advice) without modifying the code itself, instead separately specifying which code is modified via a “pointcut” specification, such as “log all function calls when the function’s name begins with ‘set’”. This allows behaviors that are not central to the business logic (such as logging) to be added to a program without cluttering the code, core to the functionality.
Aspect-Oriented Programming provides a solution to implement Cross-Cutting Concerns.
Implement the cross-cutting concern as an aspect.
Define pointcuts to indicate where the aspect has to be applied.
This ensures that the cross-cutting concerns are defined in a centralized component and can be applied as needed.
This enables some of the below benefits
1. Reusable code
2. Cleaner code
3. Write less code
4. Less boilerplate code
5. Easy to maintain
Let us quickly see some of the definitions
1. Advice — Define what needs to be applied and when
2. Jointpoint — Where the Advice is applied
3. Pointcut — a combination of different Jointpoints where the advice needs to be applied.
4. Aspect — applying the advice at the pointcuts