AOP and legacy code

AOP is great when you want to enhance an application but you do not want to modify its source code. This restriction may come for maintainability reasons.

A good example of this can be found in the article “Using Aspects to autonomic-enable legacy applications” by Brian Temple published at developerWorks.

Quote from the article’s intro:

Learn how to use Aspects to generate Common Base Events in any legacy Java application, without modifying the original application source. This article shows you how and also provides an example framework that can be used with your applications today.

To apply AOP of course you have to have access to the source code, but you do not necessary need to change it. AOP is a meta-programming system that adds functionality (advices) to certain points in the flow of execution (joinpoints) of the application. To match those points you have to refer to code constructs like method invocations, access to a package, throwing of an exception, etc so you need to know the names of methods, packages, exceptions, etc.