views:

323

answers:

2

Does anyone know what AOP features are different between AspectJ and PostSharp (yes I know they are for different languages and platforms)?

I'm trying to understand what kind of things AspectJ would allow that PostSharp would not, and vice versa.

+1  A: 

From their documentation of PostSharp: http://doc.postsharp.org/1.5/##PostSharp.HxS/UserGuide/Laos/AspectKinds/Overview.html

Supported types of join points: http://doc.postsharp.org/1.5/##PostSharp.HxS/UserGuide/CoreLibrary/CodeWeaver/Overview.html

AspectJ provides a great deal more flexibility as the join points can be decidedly more complex, in order to do what you want.

It appears that cflow, for example, can't be done with PostSharp.

It is like Spring in that it is a stripped down version of AOP in order to make it easier to use.

Update: Though I don't believe it is completely updated, this is a good idea as to what AspectJ supports: http://www.eclipse.org/aspectj/doc/released/progguide/index.html

James Black
Do you have similar links for AspectJ that document the supported join points?
LBushkin
AspectJ is in flux and the documentation is lagging, so your best bet is get the book from Manning Publications: http://www.manning.com/laddad2/. AspectJ has enough flexibility that it is really easy to hamstring yourself.
James Black
+1  A: 

PostSharp 2.0 is much closer to AspectJ than PostSharp 1.5 was. The comparison of PostSharp 1.5 to Spring AOP was justified, but is not any more with PostSharp 2.0.

However, there are still some strong differences in approach.

  1. The approach to pointcuts is radically different. AspectJ provides a complex pointcut language. PostSharp provides a basic declarative pointcut system but enables you to develop imperative pointcuts, so you can write code (typically using System.Reflection) that evaluates the pointcut at compile time. So instead of having a pointcut language, PostSharp supports plain C# or Linq.

  2. There is indeed no conditional pointcut (cflow).

  3. PostSharp supports semantics of higher-order, like events and properties. AspectJ, to my knowledge, does not (since there is no event or property in Java afaik).

  4. PostSharp aspects are typically instantiated and initialized at build time, then serialized into the assembly, and deserialized at runtime to be executed. This allows the aspect to "initialize" at build time, so runtime performance is better. It allows also to execute arbitrarily complex logic at build time (typically initialization, pointcut evaluation, joinpoint validation).

  5. PostSharp has real support for aspect composition, i.e. you can apply multiple aspects or advices to the same joinpoint in a predictive way. PostSharp is designed for a multi-vendor scenario, where multiple aspect vendors don't know about each others. It has a complex system of dependencies, where aspect developers/vendors can specify declaratively ordering constraints, requirements and conflicts.

From version 2.0, PostSharp comes with IDE tooling that partly cover the functionality of "AJDT" for Eclipse.

Gael Fraiteur