What is Aspected Oriented Programing?
AOP is programming pattern to add additional functionality to the exiting functionality with distrubing the existing code.
Before jumping into AOP we must understand about a term called as concern. Concern is a piece of the functionality in the application. There are two types of concerns, named as Core concern and Cross Cutting Concern.
Core Concern is generally called as business logic of the application, Cross cutting concern is a secondory fucntionality adding additional functionality at before execution of business logic or during the execution of business logic or after execution of the business logic.
Example for core concern
In a Student Management System caleculating Students average in final exam and finding fee due and finding attendance average are examples for Core Concerns where main business logic of the application is including
Example for Cross cutting concerns
In a Student Management System if we want to know list of actions executed while performing core concerns, then we need write logging functionality and then we need to invoke or call logging method before executing core functioning, So here logging called as cross cutting concern.
Core Concern is called a business logic of the application.
Cross Cutting is a secondary functionality in the application like logging, security checking before executing a perticular action in the application
What is Aspect?
Aspect is a collection of cross cutting concerns, that means cross cutting concenrs are created or modularised into Classes which are called as aspects
Aspect is a class in AOP which is a collection of cross cutting concerns defined.
For better understanding the nature of aspect in AOP, we can compare a class of OOP with aspect in AOP
aspect in AOP is similar to class in OOP
Important terminalogy in AOP
Aspect
Aspect is the implementation of cross cutting concerns
JointPoint
JointPoint is point where corss cutting can be executed in the execution flow application, JointPoint is nothing but point where we can execute/initiate the execution of aspect. Simply JointPoint can be a method execution, exception hadling or chanding the value of object variable in the main application execution flow.
PointCut
Pointcut is an expression to tell that when Adice need to be executed, Pointcut selectes the joint point, at which joint point Adivce need to be excuted.
Point cut is a pattern or expression to identify at which Joint Point Adivce need to be executed.
Advice
Advice is an action which will be executed at specified joint point. Adivce will be executed before method execution or after method execution or during method execution.
Target Object
Target object is an object on which advice is being applied.
What is spring AOP
Spring AOP is allowing us to implement AOP into our spring boot application. To create Aspect just we can annotate a class with @Aspect annotation.
Types of Advices
There are five different types of Advices based on the execution position with respect to jointpoint
Before Advice is an advice which will be executed just before jointpoint
After Advice is an advice which will be executed after jointpoint( normal execution or exception thorwn in both cases this will be excuted)
Around Advice is an advice which will be executed before and after the jointpoint
Post a Comment
Post a Comment