The abbreviation of the term AOP Full Form is Aspect Oriented Programming. It is a way of organizing the high level structure of the code in order to improve the reusability and modularity by capturing joins that intersect at the cross points of many objects in a standard object oriented program. Such concerns, commonly known as, cross-cutting concerns, are generally the non-functional requirements that are manifested on the system level almost in all the program elements of and including logging, security, or error handling.
Key Concepts in AOP:
- Join Point: A point in the implementation of a program which a cross cutting concern can be joined. This includes the method calls, the fields access, the constructors and exceptions.
- Point cut: An aspect that outlines a set of join points that the specific cross cutting concern is to be connected. Point cuts are generally described by regular expressions or declarative statements.
- Advice: A discrete segment of code that is implemented at a join point stated by a pointcut. Advice can be of three types:
- Before advice: This kind of aspect is executed before a join point is achieved.
- After advice: Called thereafter the join point is reached is reached irrespective of whether the join point is complete without throwing an exception.
- Around advice: Runs before and /or after the join point and can decide whether the join point will or will not be invoked.
- Aspect: A piece of code that implements a regularity that needs to concern multiple non-sequential modules, intenders and advice. Applying Aspects requires the use of a technique known as Weaving.
Benefits of AOP:
- Improved Modularity: AOP is a useful method when it is necessary to separate something that cuts across several object types because its application results in better modularity and reusability.
- Reduced Code Duplication: Global policies may be used once in an aspect and applied every where in one or more modules without code replication.
- Increased Flexibility: Through aspect oriented programming, it is easy to implement and manage cross cutting system, since the applied aspects are uniquely distinct from the program baseline code.
- Enhanced Maintainability: By the structure of the problem AOP can make code more comprehensible and malleable since related cross-cutting concerns are collected together, so to speak, so that they can be determined and altered more efficiently.
Example:
Suppose we have a requirement to implement a logging system of a hypothetical logging system in a real-life web application. Even in a more orthodox object-oriented architecture, you would likely find logging code scattered all over the application, which rather complicates its management and further evolution. With AOP the approach is to create a logging aspect that defines the point of method calls and a before advice that specifies the generation of a log message just before the method is executed. From here it can be generalized to the entire application in order to log all the method calls without altering the basic code.
Finally, AOP is a very strong concept of programming that can enhance the modularity, maintainability, and flexibility of software systems. AOP can provide the ability to cleanly separate out cross cutting concerns from core business functionalities and also can enhance the quality of code in terms of reusability and maintainability.