Aspect Oriented Programming

The following is a link to an interview with Gregor Kiczales on the java site www.theserverside.com The interview provides valuable insights into exactly what AOP is and how it can be used. It is obviously geared to the Java developer but the concepts he discusses and implements will have a strong influence on any .Net implementation.

He makes an interesting point about the implementation of cross-cutting concerns. Specifically:

“In AOP terminology, weaving means the coordination of the crosscutting aspects with the rest of the code. So it can be done by a pre-processor, a compiler, a post-compile linker, a loader, the JIT or the VM.“

I have heard people mention that AOP must be an extension of the language. Gregor makes the argument that static (compile time) is also a perfectly acceptable implementation as well (AspectJ's primary implementation). He also points out that it could be sometime before it is adopted as part of the Java language so some form of interception, pre-compile, post-compile, etc. is mandatory at this point anyway. .Net has the same issue as well. Personally, I like the compile time option because it negates the need to handle everything via MarshalByRef but then again I can think of situations where dynamic (e.g. interception) would make perfect sense. AspectWertz and others are following the dynamic approach. In the end though, interception predisposes you to a class model; whereas static (compile time) does not. But then compile time changes mean you then have to handle different compilers which are on the rise (mono, sidewinder, rotor, etc.). So pick your poison.

AOP can also aid in the concept of Design By Contract. This is something I have messed around with a bit with my validation framework discussed on TheServerSite.Net. I have been playing around with ResolveCorp's XC# for compiler extensions and the soon to be deprecatated ContextBoundObject. I keep toying with the idea of creating an open source project for AOP and C#. I have seen a few out there and have not been too impressed and the ones that I like and show some promise are purely academic.

No Comments