Home > Programming > AspectF in Java

AspectF in Java

AspectF is a Fluent Aspect Framework written in C# by Omar AL Zabir. It helps reduce on the plumbing code. For more information about AspectF framework, you can read an article by Omar AL Zabir on code project. There are different aspect frameworks you can choose from, for C# there is postsharp, Castle.DynamicProxy, LinfuDynamicProxy, Sprint.Net etc and for java there is Spring, AspectJ etc. My experience in .Net is with Postsharp and AspectF. When it comes to java, I have played around with Spring AOP but I haven’t found it easy as with AspectF in .Net. I took the decision to convert AspectF by Omar AL Zabir in C# to Java.

AspectF is easy to adopt, easy to extend and rocks!, thanks to Omar AL Zabir. With that I went on the adventure of converting AspectF C# code to Java. Main C# features used in AspectF C# that needed to be converted to Java included:-

  • Delegates: I had to create abstract classes Action, Func, IDelegate to account for the corresponding delegates in .Net
  • RunAsync: In C# it uses the BeginInvoke and EndInvoke for Java I have used the ExecutorService with a thread pool of 20.
  • TimeSpan: I created a simple TimeSpan class to be used in the timing calls.
  • C# Extensions: Since java doesn’t have extensions, I decided to merge the calls in AspectExtensions to the same class as AspectF

Methods I skipped converting include MustBeNonDefault and CacheList

I did use the same tests in AspectFTest class to make sure the conversion was atleast in a working condition.
For mocking I used the mockito which is as simple as Moq. The tests confirm to JUnit with some rough edge changes from xUnit.net.

The conversion wasn’t smooth since I had to hack my way around the Action and Func C# delegates.
As of now there is a hacked Alpha version which needs further improvement. Am currently using it in my small projects and will improve it further as need arises.

Download AspectF in Java
NB. NetBeans 6.9 was used to build solution

Categories: Programming Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: