0

I started to be interested in Aspects in Java, however I am having difficulties for understanding the benefits and usage of Aspects. I have used Macros in C++ before. I suppose Aspects are working in a similar way. I mean "Whenever you see X, insert the code Y". Maybe I shouldn't try to use my Macro knowledge to learn Aspects.

Could you give me some concrete examples that compares Aspects and Macros to understand this better?

Erdi İzgi
  • 1,262
  • 2
  • 15
  • 33

2 Answers2

1

Macros are static code injected then compiled as a whole, where as an Aspect can be both static and dynamic, you add point cuts in your code where the code will be injected, more over aspect add logic to your method, decide whether to proceed or not. for example it is used in logging, security, transaction management...

Mehdi
  • 582
  • 4
  • 14
0

With Macros you have to indicate in the source code every spot where you want the macro to be applied.

With Aspects you define in a separate place all places that should be changed.

So if you want to add/remove an aspect, you just need to change on spot, but if you want to add/remove a macro, you have to change every location where the macro is used.

On the other hand macros are more powerful, and can be used more freely.

tkruse
  • 10,222
  • 7
  • 53
  • 80