tags:

views:

102

answers:

2
+2  Q: 

AspectJ problem

Hi I am new to AspectJ and I would like to find out if creating variants of a class using Aspects - I will create another instance of the class as well?

A: 

What do you mean by variants? If you are asking if AspectJ instantiates copies of your class, the answer is no. AspectJ uses a design pattern called proxy to intercept calls to your class.

Miguel Ping
Spring AOP uses a proxy. AspectJ will modify the bytecode, either by weaving in the changes, or as part of the compilation.
James Black
+1  A: 

I am guessing that the question is, if I am adding aspects would a new class be created.

The answer is no, as the weaving, either when compiling or at run-time, using AspectJ, will add the changes to the classes that are affected by the aspects, so there is no new class created, it is just that the byte code for the original class and the final class are different.

James Black