|
Val's Blog
Lots of stuff for Web 2.0 freaks and Javaholics
|
|
|
Alan Kay: "90% of code written today is getting around other people's mistakes." |
[ Login ] |
|
For those of you who intend to take the AOP pill sooner or later, it is important to know that there are two main trends out there, namely solutions that achieve AOP by:
When AOP adoption is at stake, choosing one or the other solution may not be as straightforward as it seems. In this blog, I will try to make an objective, yet non-exhaustive, comparison between the two of the biggest actors on the AOP scene, namely, AspectJ and AspectWerkz.
The AspectJ community has created a seamless extension to the Java language with a bunch (> 20) of new keywords (
In AspectWerkz, aspects are Java classes (+ attribute If you decide to go with the first solution, you will need to integrate the AspectJ compiler into both your development environment and process. Moreover, you will have to learn the new syntax and semantics AspectJ adds to the Java language. While AspectJ provides several modules that you can plug into your favorite IDEs, it might not always be the best solution depending on how open your company is when it comes to adopting new tools and/or languages. In contrary, AspectWerkz allows one to define aspects using conventional Java syntax and semantics, i.e., all aspect-related code is declared using javadoc-like attributes written in class, field and method comments which might lower the learning curve necessary to get your first advanced HelloWorld running.
Now, I am going to discuss an example (shown in Figure 1 below) taken from the AspectJ Programming Guide that I have sort of re-implemented with AspectWerkz in order to provide a very basic comparison between both solutions. Of course, the example is pretty academic and not really complicated, but it's a good start... Also, note that the
The first thing that comes to mind when seeing this figure is that the AspectJ code is more concise. For instance, there is a code overhead in AspectWerkz's
I don't mind the Mixin stuff for implementation introductions, but the supplementary line for retrieving the context variables in the advice do bother me actually. Why AspectWerkz does not consider letting one specify the pointcut context variables as parameters to the advice method? This would be quite equivalent to AspectJ: we would be able to keep the JoinPoint parameter (AspectJ's
Another thing that kind of annoys me is that AspectWerkz has only a conceptual notion of abstract pointcuts. In AspectWerkz's example on Aspect inheritance, we can see that the abstract aspect
AspectJ also provides other inter-type declarations( I have been using AspectJ since the first beta versions and I have always been quite happy with it. However, even though AspectJ excels at type-based crosscutting, I still think that it lacks proper techniques for achieving *true* instance-based crosscutting. JBoss AOP and Spring (which I haven't talked about in this blog) are said to achieve this goal but I'm not completely satisfied with those solutions. I'm still looking into how AspectWerkz could provide a better solution to my problem. I'll probably write an update about this problematic in the near future. As a conclusion I would like to stress that my goal was neither to promote one solution over the other nor to provide an exhaustive comparison between AspectJ and AspectWerkz. There are many other details about both technologies that I haven't talked about. I just wanted to highlight some differences and similarities that I have found between both solutions. Finally, if any information that I have stated in this blog is innacurate, please do let me know.
Update: Thanks to Jonas Bonér for spotting one mistake in the AspectWerkz code.
TrackBacks[0]
Comments[4]
Posted by val on June 1, 2004 12:45:42 PM CEST
Reply |
Permalink
Re: AspectJ and AspectWerkz compared... sort of...
Thanks for a good comparison.
But actually you would not write the AW advice the way you have written it. The Point is the target instance, right? So it is retrieved like this:
Point p = (Point)jp.getTargetInstance();
A little bit better :-)
Comment from Jonas Bonér on June 2, 2004 9:25:10 AM CEST
Thank you Jonas. My mistake. I have made the changes and updated the text accordingly.
Comment from Val on June 2, 2004 9:47:29 AM CEST
I just wanted to add that you are absolutely correct in your critizism. This is something that we need to work on. I have planned to impl. support for args(), target() and this() in the summer.
Thanks.
/Jonas
Comment from Jonas Bonér on June 3, 2004 9:15:52 PM CEST
At the time of the blog writting, it was indeed the case.
Since AspectWerkz 1.0.RC2 we support the AspectJ "args(<your args, ..>)" syntax to gain direct access to the advised method/constructor/field set in the advice.
Support for this(..) and target(..) as showned in the comparison is in our CVS since some days, and will thus be part of the next release.
At that time it would be interesting to repost such an article :-)
Alex
Comment from Alex Vasseur on October 8, 2004 10:21:45 PM CEST
TrackBack to http://radio.javaranch.com/val/addTrackBack.action?entry=1086086742000
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Content © Val | Powered by Pebble 1.9.1 |