I just attended an extremely interesting session entitled Architecture Enforcement with AspectJ and Other Tools given by Alef Arendsen and Ramnivas Laddad. They first showed Structure101, which gives you a visual representation of your architecture, including displaying package structure, cyclic dependencies, etc. I hadn't heard of Structure101 previously. It looks like there are several versions including both free and for-fee.
They next showed several examples of using AspectJ to enforce architecture rules both at compile-time and runtime. This included rules like:
- don't use straight JDBC, instead use Spring JDBC
- don't return null Collections
- ensure that non-thread safe objects are never accessed by multiple threads simultaneously
It was all AspectJ plus Java. Very cool! The compile-time errors show up as standard compile errors in Eclipse and the runtime errors can be exceptions or some type of log message using Log4j or similar. This presents some very interesting options if you're working on a medium to large-sized team and want to enforce a clean architecture. I can already think of a number of places that this would help us immensely. It sounds like it's well worth the investment. Obviously you'll still want to have a Software Architecture document, but this gives you a way to enforce what's in the document.
I am a little concerned about the runtime overhead of AspectJ for the enforcement of the runtime rules, but it's worth experimenting with to see how much overhead is actually involved. I asked the speakers about this and I'm not sure they understood the question, but they mentioned the overhead was minimal. I'm worried about the case where you wind up with hundreds (or even thousands) of runtime rules and the overhead that is introduced.
No comments:
Post a Comment