Being a Java developer I felt that Cairngorm was a God sent as it provided me with a familiar way of constructing an application architecture. This made the process of starting developing in Flex a lot less complicated than if I where to start from scratch. In my old company Ezmo we built an online music service using the Cairngorm framework. We where very happy in the beginning and we really felt that Cairngorm helped us a lot as we didn’t have to learn too much about the inner workings of Flex and Action Script in order to start shipping working software.
As we continued growing our application I could not help to notice that there really was a few things about the framework that really started to degrade the quality of our code base and really made our application harder to maintain.
Boilerplate code
Writing a Cairngorm application involves a lot of boilerplate code. In order to get just a simple command going you need to create 2/3 new classes and write 20/30 lines of code which provides no value what so ever.
I really feel the Cairngorm framework should try and encapsulate more of the inner workings and hence saving developers a lot of time and effort. When designing a framework I feel you should have the approach the guys developing Spring Framework for Java has: to make development simpler. Cairngorm does not make development simpler and as your application grows Cairngorm really starts to slow you down.
More code, more problems
Numerous studies has shown that the more lines of code you have in your application, the higher is the potential for bugs. Therefor it would be beneficial for an application framework such as Cairngorm to let developers write less code. In my experience Cairngorm does quite the oposite. I have compared an application created using Cairngorm to the same application written from scratch with a custom architecture and Cairngorm adds numerous classes and several hundred lines of code (I’ll provide samples of this later on).
Feels like EJB 2.0
When I work with Cairngorm I get the same feeling as I did back when I had to work with EJB 2.0. It feels like a plastic bag that’s constantly over your head while you try do develop your application. The framework is intrusive and continues to force you to write tons of useless code and transforms all applications intro dinosaurs that become hard to maintain and really hard for new people to learn. Regardless of all the patterns used in Cairngorm, it is not easy for new developers to start developing when they have to related to such a huge number of classes.
MVC is probably not what you need
In my experience most applications don’t need to implement the Model Control View pattern in order to provide a decent application architecture. Especially I feel this is the case for Flex, you really don’t want to mimic a Java web application when you have such a great framework as Flex!
A plead to Adobe Consulting
Listen Adobe Consulting, either you try and upgrade your framework to something that fulfills the demands of developers in 2008 or you release it as Open Source. Right now all the new things in Caringorm are related to their ridiculously expensive Live Cycle Data Service, nothing in regards to making development faster and easier. If you don’t have the time or resources to do this, release it and maybe the community can help out (I am fully aware that I should put my money where my mouth is and develop my own framework, but this is not something I have time to do right now).
Here is what you should do
Having put down the Cairngorm framework I guess you want to know what to do? OK, I’ll try and elaborate some of my thought on how you best construct and application architecture in Flex.
Model Locator & Business Delegate
There are two valuable things in Cairngorm which I would continue to use (but I would probably just develop those classes my self for each project):
- Model Locator
- Business Delegate
All the command, event, front controller mumbo jumbo is just there for the pattern horny architects who does no actual coding and have a need to have as many patterns as possible in every application architecture the work on.
Now here is why I feel these things make sense for almost any project. The Model Locator pattern, as Adobe calls it, is a great way to control data in your application. Combining the Model Locator with the built in feature of data binding in Flex that is a really powerful combo. If you combine this with a Business Delegate class you have pretty much all you need (you may not actually need that class either, it is not very hard to write one on your own).
Why settle for just one model?
If you decide to throw out most of Cairngorm and write your own architecture I would advice you to use two types of Models: Presentations Model and Server Models.
Having a one-to-one relation between the server side services and Server Models provides you with a seperation between server side data and the presentation data. Server Models should be responsible for retrieving their own data (that’s right, no events/commands needed). Presentation Models can use one or more Server Models, and once again using data binding to control updates. I think this provides a really simple, but yet very scalable, application architecture.
Update
I am terribly sorry about the mistake of not remembering that Cairngorm is Open Source. Since I wrote this I have been notified about some other articles dealing with the same issue and I think the best one yet is an article called Using Cairngorm & Thoughts On Handling Those Pesky Singletons
.
Please see recent post to http://weblogs.macromedia.com/swebste r- Cairngorm will be moving to opensource.adobe.com in the very near future, in order that we can more easily accept community contributions. In addition, there are other Adobe Consulting blogs (and presentations such as Flex 360 and MAX) where we’ve also shared our views on presentation model patterns alongside (not instead of) Cairngorm. We endeavour to publish more around how we use Cairngorm in the near future.
Comment by Steven Webster — May 26, 2008 @ 8:29 pm