Aspect-oriented-programming is a technique that helps to separate the system service(concern) from the core business logic. System services are like logging, security, transaction management, exception handling, etc.

The Advantage of using AOP are:
1)The business component looks very clean having only business logic.
2)All system services are implemented in a commonplace that simplifies code management.
3)Clear separation among the developer.

AOP Terminology
Every system service is an aspect like logging. exceptions etc.

Advice is the actual implementation of an aspect i.e. it defines the job that an aspect will perform. Advice defines both what and when of an aspect.

Advice typeInterfaceDescription
Beforeorg.springframework.aop.MethodBeforeAdviceCalled before target method is invoked
Afterorg.springframework.aop.AfterAdviceCalled after the target method returns regardless of the outcome
AfterreturningOrg.springframework.aop.AfterReturningAdviceCalled after target method completes successfully
AroundOrg.aopalliance.intercept.MethodInterceptorBoth Before and After
Afterthrowingorg.springframework.aop.ThrowsAdviceCalled when target method throws an exception.

A joinpoint is a point in the execution of the application where an aspect can be plugged in. Spring only supports method joinpoints.

Pointcut help to narrow down the joinpoint instead of applying advice on all the joinpoint.

A proxy is an object created at runtime after applying advice to the target object.
Proxy = target + advice(s)

The target class is a pure business component that is being advised. Without AOP, this class would have to
contain its primary logic plus the logic for any cross-cutting concerns.

The process of applying aspects to a target object to create a new proxied object.

Combining Advice and Pointcut where the advice should be executed is called Advisor.
Advisor = Advice + Pointcut(s)

Leave a comment