Aspect-Oriented Programming

I found this on PHC’s website, must be the cleanest explanation I’ve seen of aspect-orient programming:

Aspect oriented programming is a relatively new programming paradigm. The standard example to explain what AOP does for you is the following. Suppose you have a script with a series of functions. Say you want to start and end every function with a call to some logging function:

   function some_function
      log("some_function: begin");

      /* do whatever the function should do */

      log("some_function: end");

And say you want to do that in each and every function, for example for debugging purposes. It’s a lot of work to do that manually for every function. And when you no longer need it, it is a lot of work to remove it again. This is what’s known as a cross-cutting concern: something you need to implement (in this example, logging), that “cross-cuts” (affects) a lot of code. With AOP, you can write this concern as a single “aspect”. You then run your program through an “aspect weaver”, which will insert the necessary code at the start and end of each function, thus saving you a lot of work.

Other Entries

Tweets from