Yesterday, Chiara sent me a link to Rickard's J2EE Redux. Great to read that, 9 months later, now that I came to the same conclusions. I haven't read
that post - I wasn't even reading blogs back then - and it's kinda
funny that I ended up reinventing most of the things Rickard is talking
about there, and made a lot of noise about it. I felt a little ashamed
to be making all this buzz of it, months after somebody already
walked the same path, but, you know what? If it's something I consider
good and that deserves more attention, why not? :)
So, set back your clocks to Oct 16, and let's take a look at what Rickard has to say:
You can kind of use it at work tomorrow, if you use AspectJ or HyperJ or any of the other current packages that does AOP in Java
Hmm, guess we made a lot of progress, here, haven't we? Now we've
got AspectWerkz, Nanning and JBoss-AOP, just to name the ones I saw
being talked about the most. AspectJ is now an Eclipse project, and Hyper/J...well, it's still basically the same.
AOP, to me, is two things: first, you get to pick objects apart into
smaller parts each of which has a nice clearly defined purpose. These
parts can then be assembled to form big objects. If the parts are
reasonably cleverly thought out they are very reusable.
I don't think Rickard's being as extreme as me, here - my objects are
all empty, and entirely made of smaller and pretty testable parts, but
the idea was already there, and it's still pretty much the same. And I
must repeat this: I've never seen a system that's so reusable, and that
has so little code to do what it does (even counting XML configuration
files). It's all about the tools, buddy :)
Second, AOP is also about what most people would call "interceptors".
That is, doing stuff before and after a method call on an object.
Anyone still doubts that interceptors rock? Recently, Cedric helped
create a new kind of interceptor, triggered by a caller-side pointcut.
Jonas implemented it in AspectWerkz, and I'm sure others will follow
soon. Today, still, the most researched part of AOP is interceptors,
and more powerful pointcut selection languages are coming around - just
look at AspectWerkz' recent release, 0.6.3 - it's awesome :)
Well, in AspectJ there's a funky Java language extension that is used
to define "joinpoints" which is basically a regular expression
determining what classes should get this stuff. IMHO that's a sucky
approach, because then you need to modify the interceptor each time you
want to apply it to something new. In my own implementation I've used
(... drumroll ...) XML to define these relationships.
Interesting to know that people already disliked AspectJ because of the
language extensions back then. I didn't even bothered to look at AOP until a
decent pure-Java AOP framework came out, the difference here is that
Rickard had the time and skills to implement his own AOP framework at the time. I certainly didn't. :)
After all these months, we had some talk about whether using XML to configure
aspects or not, and I must say I'm particularily inclined to think that every
configuration should be on a configuration file, even if it's not XML -
I love WebWork's views.properties, for example - contrast that to
Struts' struts-config.xml -, and passing around lots of hard-coded
strings and .class attributes means configuration to me. But Jon Tirsen
has pretty valid points to suggest that configuring things using plain Java
code is a good thing, refactoring support being the strongest of them, to me, and
Nanning is getting more interesting at every release.
It's that simple, really. To paraphrase a saying we happily shout a
couple of times a day over here: "It Just Wooooorrrrkkksss!!!"
I agree - it's a very simple concept that leads to very simple code,
great mantainability, and, given the right tools - I put up a lame
AspectWerkz definition file editor in XMLSpy and I'm using it with
reasonable success, great manageability of your objects.
I'm still trying to imagine how a bunch of swedish geeks shouting might
look like, but that doesn't have anything to do with the subject, so
nevermind :)