Thursday, September 15, 2011

Implementing Aspect Oriented Programming Framework - Java Instrumentation

What is Aspect Oriented Programing: Aspect Orented Programing or AOP is a design pattern or programming practice, in which the code for cross cutting concern is separated out from the main program logic, thus effectively reducing the program complexity. Now what is a cross cutting concern? They are application non-functional requirements that apply to multiple functionalities. A simple example would be logging. Logging is done whenever some predefined things happen (for example a method is invoked). Normally, every method that is invoked would have to contain the code for logging. In AOP, we write the logging code in a separate method may be in a separate class and then configure our AOP framework to do logging whenever a method is invoked. There are so many good tutorials available on AOP, one of which is here. However, in Java SE environment, it certainly requires a change in the method's byte code made by the AOP framework. I will demonstrate how an AOP framework performs load time weaving (changes byte code during runtime).