Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Usage of AOP

 
tabiul mahmood
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All AOP Expert,

This is more of a design question on AOP Usage. The classic usage of AOP has always been in security/logging/transaction etc. I am thinking of using AOP in more business context. I have a method that I need to call across multiple modules in some specific method. Is AOP appropriate here? The business method is not a pure Cross Cutting concern that affects all methods in the application but it does impact significant places. My thinking is that by using AOP can a centralize my code in a single place and prevent tight coupling as maybe I will change the signature of the method and then I will need to change all code that is calling that method. A friend of mine said that AOP should not be used as AOP should only be used non domain or business context.


What do you guys think?

Thanks

Tabiul
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use AOP with caution. AOP gives illusion of simplicity, but actually it's more difficult to understand. Using Annotations is a way to make AOP easier to understand but still not clearest.

If you want to centralize your code, I think you can do without using AOP.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree and disagree. It always depends on the use case. Is this something that you might want to remove later, or turn on and off at your whim. Then AOP is a great choice for it. Do you mind all the clutter/tangling code of the process in all your other code, that is needed but doesn't represent the Use Case of the method that you tangle this code in? Then AOP is a great choice for it.

But AOP is not the choice for everything. You really need to weight the pros and the cons, and know that sometimes debugging or determining where an error is coming from that might or might not be from AOP can be a little more difficult. Not with a great IDE that you can set break points, but sometimes you have to have two break points. One in the code before the AOP gets called, and one after in the real code. Because Proxies are being used.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic