Traditional programming techniques - from procedural to object-oriented programming - have privileged the functional aspect of applications. The modelling techniques upon which they are based are targeted at modelling functional behaviour and the principle of separation of concerns is applied by organizing an application as a set of cooperating functional units (where, depending on the particular programming paradigm, a functional unit may be a procedure, a module, an object, a class, etc).

Once implementation in a conventional class-based language is selected, however, it will normally be impossible to localize the code that implements the error-handling aspect of the application. Assume for instance that all application methods return an error code that indicates whether the method completed successfully or whether it encountered some error. Then, simple examples of error handling policies at component level are:

The code that implements the above policies is spread over the entire code base of the target application (or, using the standard AOP terminology, the error handling aspect cross-cuts the functional aspect). This means that changing the way the aspect is implemented (i.e. changing the error handling policy) requires global changes to the application code base. This is far more expensive and error-prone than would be the case if the implementation of the aspect were localized in a dedicated "module" (i.e. if the principle of separation of concerns were applied to the error-handling aspect as well as to the functional aspect).

AOP as Code Generation

The yellow boxes represent the starting code. This is organized as a set of modules. The green box represents an aspect program that defines a particular code transformation. The aspect weaver is a compiler-like program that reads the aspect program and uses it to modify the base code and automatically generate a new base code modified to implement the desired aspect. Note that both the base program and the modified base program are written in the same language.

The important point to note is that now error handling is encapsulated in a dedicated module (the aspect program). Changes to the error handling policy are localized to this module and can be quickly and safely implemented and then projected upon the entire base code by the aspect weaver. The principle of separation of concerns is now applied both to the functional and to the error handling aspects of the application.

AOP as Compiler Extension

The yellow boxes represent the base program written in a conventional language. The green box represents the aspect (meta-)program which specifies a new aspect that it is desired to project onto the base program. The aspect program is compiled by the aspect compiler that produces an extension to the standard compiler of the base language. This compiler extension is then combined with the base language compiler to generate an extended compiler and this is used to compile the original base program. The object code that is generated by the extended compiler encodes both the behaviour defined by the base program and the aspect defined by the aspect program.

Language Support

Contact Us | The OBS Framework Project