The AOP Implementation
The AOP implementation performs two logical steps: It first combines the individual concerns using the weaving rules, and then it converts the resulting information into executable code. AOP implementation, thus, requires the use of a processor—weaver—to perform these steps.
The weaver can be implemented in various ways. A simple way is through source-to-source translation. Here, the weaver processes source code for individual classes and aspects and produces woven source code. A regular language compiler may then process the formed code. The aspect compiler then feeds this converted code to the base language compiler to produce the final executable code. Using this approach, a Java-based AOP implementation converts individual source input files into woven Java source code and then lets the Java compiler convert it into the byte code (in fact, this implementation technique was used in early implementations of AspectJ). This simple approach suffers from several drawbacks as the executable code cannot be easily traced back to the source files written. For example, stack traces would indicate line numbers in woven source modules.
Another approach could be that the source code would first be compiled into class files using the base language compiler. The class files would then be fed to the aspect compiler, which would weave the aspects into the class files to produce woven class files. Figure 1 shows a schematic of a compiler-based AOP language implementation.
It may also be possible to push the weaving process close to execution of the system. For example, if the implementation of AOP is Java-based, a special class loader or a VM agent could perform the weaving. Such an implementation will first load the byte code for the aspects, weave them into the classes as they are being loaded, and supply those woven versions of the classes to the underlying virtual machine (VM).
Yet another implementation possibility is through use of automatically created proxies. In this case, each object that needs weaving may be wrapped inside a proxy. Such implementation typically works well in conjunction with another framework that controls creation of objects. In this way, the framework can wrap each created object in a proxy.
So far, we have looked at the mechanics of an AOP system. Now we take a look at the fundamental concepts behind AOP.