Jeff Barr's Blog

Things I Like..

Aspect-Oriented Programming

AspectJ CookbookLast week, Russ Miles, author of the Aspect J Cookbook, paid a visit to Amazon to talk about Aspect-Oriented Programming. I’ve blogged his talk here.

Aspect-Oriented Programming (AOP for short) has a whole new vocabulary, including neologisms like pointcuts, aspects, concerns, and join points. In a nutshell, aspect-oriented programming allows separation of code in to a number concerns. Each concern is some particular kind of thing that the code has to do, such as logging, transaction management, persistence, and so forth.

In a traditional OOP (Object-Oriented Programming) model, these concerns would be factored out into a fairly fat base class. This is a very common model for GUI toolkits. The object model for such a toolkit almost always has a base “item” class with methods such as load, store, draw, handle event, and so forth.

Using AOP, it is possible to forego the base class. Each concern is implemented separately and independently of the others, and then attached to the basic code in the appropriate locations, known as join points. A join point can be the entry to a function, the exit from a function, the calling of a method, and so forth. The pointcuts attach the concerns to the join points. The flesbility will vary with the base language and the AOP implementation. In the implementation that Russ showed us last week, it was possible to use a regular expression to denote the set of functions to be attached (cut? joined?). In this way it was possible to capture control before any method with a name that begins with “Get” was called.

The entire technique is fascinating, and I want to learn more. I have not written any Java code for a while, so I probably won’t be using AspectJ. There are other AOP implementations and implementation proposals including Aspect C and PHP.

Visit the AOSD.NET site for even more info.

Of course there are already a fair number books on aspect-oriented programming:

Eclipse AspectJ : Aspect-Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools”Aspect-OrientedAspect-Oriented Software Development with Use Cases (Addison-Wesley Object Technology Series)