Thursday, March 03, 2005

Practical AOP: The Case For Aspects

This presentation on AOP was given by Bill Burke, the Chief Architect of the JBoss Group. Mostly, this symposium has featured notably professional and sharp presenters. Mostly. Bill would be the exception to that... He mumbled through the presentation and hadn't seemed to put a whole lot of thought in what he wanted to say. Nevertheless, some interesting information came out of it. F for style, B- for content.

If nothing else, the presentation was useful for giving an introduction to the basic vocabulary of Aspect Oriented Programming (AOP).
  • advice: like an interceptor, an event-handler for execution
  • aspect: Java class that defines advice
  • pointcut: AOP query, declaratively (XML) inject interception
  • invocation: a runtime construct of what is intercepted (method, constructor, etc)
He offered two basic examples of good use cases for aspects.

First, SQLException obscures the actual error message thrown from the database. Different vendors provide different codes for common SQL errors, so it is impossible to generically cast strongly typed SQLExceptions. But, thanks to aspects, you can intercept any method that throws SQLException and implement the logic to map vendor error codes to recast the thrown exception into a more strongly typed class.

Second, you can enforce the Singleton design pattern without the boilerplate code in the class itself. Instead, you can intercept any constructor invocation around the class and force the method to return the singleton instance of the class.

The rest of the presentation drifted more and more into specifics of JBoss AOP, and much of it was hard to follow. It was a useful presentation to the extent that it provided good, pragmatic examples of how AOP can add value.

1 Comments:

Anonymous Anonymous said...

Joel, I'm curious. Did you get the feeling that you could mix & match AOP with OOP to get the best of both worlds depending upon what the situation called for?

10:33 PM  

Post a Comment

<< Home