1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Friday, June 12, 2009

Choosing a Flex Architectural Framework

Bill Gloff » Cairngorm
Friday, January 30th, 2009

If you're working on a moderate to complex Flex/Air application I hope you are using some kind of MVC style framework to help with organizing your components and the interactions between them. If you do not use a framework, you will unknowingly be creating your own. This, consequently, makes it harder for others to get up to speed with any maintenance that will need to be completed, and you will be on the hook to create all the related documentation. Also, why re-invent the wheel when pre-existing frameworks, such as Cairngorm, PureMVC, Swiz, or Mate, already implement best practices and are field-tested? All you need to do is set aside a little time to learn them.

I'm currently working on a greenfield project where I have a Flex/AIR front-end talking to RESTful services provided by Groovy on Grails. I'm a few weeks into the project, but my latest challenge has been deciding on what MVC ActionScript/Flex framework to use. Let me attempt to tell you a little about my process thus far, in case you're going through this yourself.

If you've done any Flex at all I'm sure you've heard about the market-leading framework Cairngorm. It's currently the most popular choice for enterprise worthy applications. It took its inspirations from the Sun J2EE Blueprint Catalog and implemented all the Java based patterns in ActionScript (AS). Some of these well-known patterns are the Command, Front Controller, MVC, Singleton, Value Object, and the Delegate. I believe some reasons for the success of Cairngorm is because AS is very similar to Java with a little mix of JavaScript thrown in for good measure. Then, you add the fact that Adobe (and previously Macromedia) likes targeting server-side Java guys (LiveCycle Data Services anyone?), which should make them comfortable with Cairngorm once they get up to speed on Flex and AS. Since it's been around for a long time there's quite a bit of documentation on it (in blogs, as well as books), and even code generators, which attempt to speed up development time. In Flex Builder 4, which will be released later this year, Adobe will be integrating Cairngorm support into Flex Builder out of the box. Very appealing indeed!

I know PureMVC is getting a lot of hype lately as it enforces a strict MVC and has been ported to a lot of different platforms such as Java, AS, and even Objective C and Ruby. I haven't used it, but I read up on it quite a bit. It seems a little awkward to me since it doesn't take advantage of Flex binding. I know this is because it remains a language/platform independent framework that focuses on giving you a way to do MVC. I'm sure PureMVC has its merits though, and I believe I would enjoy it if a project I was working on already had it… same for Cairngorm. The only things I would look to add to each of those would be some good ole Inversion of Control Prana style (now called Spring ActionScript) to spice things up, and simplify some of the code.

The next framework I read up on was Swiz. This seems like a great combination of MVC and IOC, and it's the only framework to use AS3 Metadata to wire up all your components. It is a very innovative approach with the only concern being maturity compared to Cairngorm and PureMVC. I probably would look into this one a bit more if it wasn't for my first choice…

I started my project thinking that I'll go with Cairngorm, but as you probably figured out, I changed my mind. This happened after I saw a demo of a Flex-based framework called Mate. In my opinion, Mate is one of the more lightweight frameworks out there. I say lightweight because it attempts to use native Flex events whereas in Cairngorm you are forced to have your events implement a Cairngorm interface. This is a dependency I do not care much for. Mate's philosophy is to make your views oblivious to what is going on in the backend… from getting some data from your server to injecting those values into your model. You can have all your custom components be free of any references to any Mate related classes, which is a good sign for an MVC oriented framework. Mate has a concept that none of the other frameworks have that I find intriguing… maybe because its different from the J2EE inspired frameworks, and I am digging how it takes advantage of MXML, whereas the others use more ActionScript. Basically, the main concept of Mate is to define an Event Map, which is just a switchboard of what actions to invoke when a specific event is fired. This is where most of your server calls come into play and injecting the values into your Managers which are singleton based models for your views and also take advantage of bindings. This Event Map is all tag based, which I like, but since it's all AS under the covers, you probably can implement your Event Map in a regular class if you prefer.

I've just begun really using Mate and I'm enjoying the process of wiring everything together. It seems well thought out and simple, but also elegant. I'm also enjoying the fact that I'm programming in more of an event-based language, which these frameworks promote, especially Mate. As I get further into my project I'll try to give updates about how my experiences with Mate are transgressing.

To get a better comparison of these frameworks you should read the 5 part article "FrameworkQuest 2008". It's a great read seeing how Tony Hillerson went and developed the same Twitter application using these 4 different frameworks and discusses the benefits and weaknesses of each.

So go and find yourself a framework to use. I'm sure whichever one you pick will work out for the best… if not, well then there's other options as you can see.

No comments:

Post a Comment

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...