Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are Annotations a kind of AOP?

Tags:

java

aop

From Oracle:

Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.

and from wikipedia:

In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. AOP forms a basis for aspect-oriented software development.

My question is: If I use a annotation like @EJB , can I say that I am using AOP? Because it seems like @EJB is a cross-cutting concern to me (e.g. resource looking up). Please explain if yes or no, or sometimes an annotation is AOP.

like image 989
Leo Avatar asked Jan 11 '23 06:01

Leo


1 Answers

Annotations are not themselves AOP, they just decorate a class, property or method with metadata. In AOP terms, you could say annotations describe "Aspects", but by themselves they do not provide any extra functionality.

AOP usually requires information to determine where to inject or provide interception. Some AOP libraries use XML to describe the places of the program in which to weave their functionality, others use annotations for this same purpose.

So, Annotations are not AOP, but rather a way of marking locations in the code where AOP can intervene and add cross-cutting concerns.

like image 178
EmirCalabuch Avatar answered Jan 23 '23 00:01

EmirCalabuch