Loading

AOP

  • AOP stands for Aspect for Programming.
  • It is a programming paradigm that allows you to modularize cross-cutting concerns in your application.
  • It helps the developer implement external functionalities to the application without affecting or modifying the business logic at the service layer.
  • Take the example of a Payment Service, Here the user needs to be logged in before making payment but you do not want to modify the code multiple times depending on your need so that you can use the AOP Paradigm.
  • Cross-cutting concerns are aspects of your application that affect multiple modules or components, such as logging, security, and transaction management.

Here you can use AOP for logging before purchasing without modifying or changing the code.

KeyPoint:

  • As the OOP is about classes and objects, AOP is about aspects.

Basic Terminologies

Some of the basic terminologies used in AOP are:

  • Aspect: It is a module or class that encapsulates a cross-cutting concern. It contains advice and point-cut expressions. It is the single unit of the AOP paradigm.
  • Advice: Advice is the action or code that you want to execute at a particular point in your program.

 There are different types of advice in AOP: 

  1. Before Advice: Executed before the method call. 
  2. After Advice: Executed after the method call, regardless of its outcome. 
  3. After-Returning Advice: Executed after the method call only if the method exits without throwing an exception. 
  4. After-Throwing Advice: Executed after the method call only if the method throws an exception.
  5. Around Advice: Wraps the method call and can control whether the method is executed and what it returns.
  • Join Point: Join points are where advice can be applied.
  • Pointcut: It defines when and where advice should run. Pointcuts use patterns to match join points.
  • Weaving: It is responsible for integrating the aspect's advice into the appropriate join points in your code