Three Examples of Aspect-Orineted Programming

Note: These examples were written in 1998 on version of AspectJ that is long obsolete. Nevertheless, I believe that they are interesting. However, they should not be taken as representative of what can be done with the current AspectJ implementation.

The utility of Aspect-Oriented Programming is best demonstrated by using aspects yourself on a large programming project. I say "large" because, as with any technique for managing complexity, the benefits are most obvious when the code base is sufficiently large that one cannot keep all of the pieces in one's head at one time.

However, before one embarks on a large programming project with a new technology, it is wise to understand what it will do for you and how it can best be used to solve the problems that will arise, To this end, I present here three small examples. They are sufficiently simple for an experienced programmer to understand them almost immediately, but they do present enough of a structuring challenge that aspects really do make a contribution. Yes, all of these examples can be programmed without aspects—but I believe that the aspect-oriented solutions are a significant improvement on the conventional alternatives.

The examples are as follows

In each case I describe the structure of the code and the development process, and provide source code.


Andrew P Black
Last updated: Last updated: 9.10.2003 at 15:45