Header Ads

ad

Spring AOP Principles

OOP Principles

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism etc..

AOP Principles/Terminologies

  • Aspect
  • JoinPoint
  • Advice
  • Pointcut
  • Target class
  • Weaving/Aspect Weaving
  • Proxy class
Note:- The languages that implements OOP principles are called OOP languages. eg:- C++, Java, C# etc..
The software that implements AOP principles called AOP enabled softwares. eg:- Spring AOP, AspectJAOP, Jboss AOP etc..

Aspect

The secondary logics that has to be applied accross the multiple classes of application is called Aspect. This logic is called called as middleware services or cross-cutting concern..

Eg:- security, loggings, transaction logics etc..

JoinPoint

The possible points/areas in the classes on which aspect logics/secondary logics can be applied are called JoinPoints. They are like fields, constructors, methods and etc..Spring supports only methods as joinpoint but methods must not be private...

Advice

It indicates when an aspect should be applied on joinPoint like applying aspect before executing method or applying at the end of the method and etc...

There are 4 types of Advices like :
  • BeforeAdvice
  • AfterAdvice
  • ThrowsAdvice
  • AroundAdvice

a) BeforeAdvice

Here Advice logic executes before executing the target class method. So once target method is executed control does not come back to advice logic/method..

b) AfterAdvice

Here advice logic executes after executing target method and before it returns the control back to caller.

c) ThrowsAdvice

Here the advice logic executes when exception is raised in method.

d) AroundAdvice

Here advice logic executes Around the target class method, i.e before and after target method..


Pointcut

It is a collection of joinpoints on which aspects are adviced(i.e aspects are configured).


Target class

The class on which we want to advice the aspects. It is pre-AOP java class having primary logics in the methods. If we call methods of target class only primary logics will be executed.


Weaving/Aspect Weaving

The process of generating proxy class is called weaving. It is all about combining multiple logics to build one proxy class.

Proxy class

The outcome class of weaving process, where primary logics and secondary logics of aspect will be mixed up dynamically at run time. It is post-AOP class.




No comments