I know a lot of developers are "warming" up to AOP and what it has to offer, but I've become increasingly disenchanted by the whole idea.What ever happened to type safety, readability, and test driven development? Things like the composite pattern, decorator pattern, etc can offer the same kinds of features that AOP offers, but with the type safety and readability.If I can't 'new' it in a main method and run some tests, I'm not really interested in using it in implementing any logic.I would be interested in hearing how people are using AOP in their applications and why?
I certainly understand your concerns and advocate cautious adoption of AOP, however in its core AOP is nothing else than macroses on steroids. Think about it as textual insertion and runtime code generation. The only difference is macro-language: in C++ we would need define those code fragments and place macro calls explicitly in the source, with AOP we can define that a certain code should surround every gettter, or every setter or something like that pattern in this class etc.
Yes, type safety can be thrown away and AOP can be easily abused, but if senior developers control AOP usage then it is quite convenient and it increases code quality and robustness.
Another misleading thing about AOP is that AOP pictured as purely orthogonal and that weaved class are not supposed to know anything about weaving. IMO it is quite opposite: AOP is properly used if system designed with AOP in mind and classes expect to be aspectized.
This is a simplistic view of AOP but works OK for a start. And to get taste of AOP you do not need to throw away type safety and convenience of IDE with all the code completion, syntax check and coloring. AW, HiveMind, and CGLib allow coding aspects as plain Java classes, which is very convenient.
You may read first part of my article (http://kgionline.com/articles/aop_1/aop1.jsp
) or look at another CGLib use for ‘pragmatic’ AOP here: http://kgionline.com/xflow2/doc/xflow2/code_tricks.html
The same effect can be achieved with AW or HiveMind easily, but I think it is somehow easier to start with CGLib proxy based AOP and then employ a full blown AOP system like AspectWerkz as you get familiar with the concept.
I have few systems in the production, which use CGLib based approach and one that is HiveMind based and I am very glad that we used AOP concept.