Why does not exist the AspectJBeforeAdvice class?

52 Views Asked by At

In Spring about AOP/AspectJ exists the MethodInterceptor interface. It is used internally to decide if an @Aspect class must be called or not - really an advice method - according with a pointcut.

About its implementations exists (see the former link):

  • AspectJAfterAdvice
  • AspectJAfterThrowingAdvice
  • AspectJAroundAdvice

Question

What is the reason or Why does not exist the AspectJBeforeAdvice class?

1

There are 1 best solutions below

0
On

This is not meant to be a conclusive answer, because I cannot speak for the Spring AOP team or speculate more than just a little bit about their design goals and motives. Insofar, this question is not a good fit for Stack Overflow, because it does not present a programming problem to be solved by a correct answer.

Anyway, actually it seems that the AOP Alliance's MethodInterceptor interface is not implemented for before advice types. Either it is not necessary or was an oversight. I think, however, that Spring AOP mostly revolves around the Advice interface and, where necessary, its subinterfaces BeforeAdvice and AfterAdvice. Moreover, all concrete advice types extend AbstractAspectJAdvice. This is a screenshot from my IDE:

Advice interface inheritance hierarchy

Please note on the bottom of the picture, that MethodInterceptor itself extends Interceptor, which again intercepts Advice. So, Advice is the common denominator for all advice types, no matter if they are also MethodInterceptors or not.