Aye Laddie, It's Cairngorm!

Cairngorm Mountains
Cairngorm may be a mountain in Scotland, but its also an architectural framework for Flex from Adobe. Cairngorm is based on the MVC model and is especially concerned with data synchronization between client and server.

A few months ago I was lucky enough to sit in on a presentation held by the New York Flex User's Group on Cairngorm. My friend, Kevin Pechin, has written a review of the meeting, but previously I had only been peripherally aware of Cairngorm, so this was an eye-opener.

Cairngorm mostly consists of design patterns originally developed for J2EE and, as was mentioned earlier, is based on the model-view-controller paradigm. If you've been in the development world for a while, this requires no explanation, but for others, the MVC model is a way of separating your user interface(known as the 'View') from your application's data(known as the 'Model'). This is important because you don't want changes to your applications UI effecting your data or changes to the underlying data to cause havoc with your UI. The controller usually talks to your Model and View and often handles events generated from the user interface (in Cairngorm these are called 'user gestures').

Data in Cairngorm is stored in 'value objects' which should be pretty familiar to most people whether they are using Cairngorm or not. If you were building an airplane reservation system, you might have objects representing customers, seats and flights. This is typical object-oriented programming. You associate your value objects with a 'ModelLocator' that helps your application locate the correct data.

Cairngorm's controller is called 'the Front' and exists to handle user gestures-it processes events and then based on the event's type, dispatches it off to the appropriate Command class. Command classes usually use the ModelLocator to obtain ValueObjects and update their data.

Although in some MVC implementations the Controller updates the 'View', this isn't done explicitly in Cairngorm; the general idea is to update the user interface through data-binding on various UI components.

Despite the fact that Cairngorm is fairly impressive, I'm not completely sold. Some of my skepticism is inherent; I'm cautious when it comes to frameworks. There's always an additional learning curve involved and I've seen enough open source frameworks come and go to make me think twice; the last thing you want is to find your project completely depending on a framework or library that's no longer supported or maintained. Cairngorm was originally developed by iteration::two which was purchased by Macromedia which in turn was purchased by Adobe; as an official Adobe framework you might think this wouldn't be a concern but the documentation on the Cairngorm site seems out of date in places. Some tutorials and examples haven't been updated since before Cairngorm 2(the current version is 2.2). What's really needed is a step-by-step tutorial that reflects current Cairngorm architecture and API's.

Like most frameworks, Cairngorm isn't really designed for small applications; what most people are building. To accomplish one thing, such as updating a select box with a new item, you'll find yourself building seventeen different classes(the controller, the commands, the model locator, etc.)

In development environments such as Flash, the other thing that makes me hesitate is download time. Developing applications in Flex leaves you a lot of baggage in bytes, something that is exacerbated by adding framework code. Weighing in at a little over a dozen K, Cairngorm is likely the lightest framework you'll ever encounter, but it is still something you should consider before plunging straight in.

Lastly, at the NY Flex User's Group presentation, Mims Wright, sitting in the row in front of me, asked perhaps the best question of the evening: how hard was it to convert existing non-Cairngorm applications over to Cairngorm? The presenter, Michal Glowacki didn't exactly answer the question, but indicated that it was on the same level of difficulty as blinking and breathing.

Still, I wonder. If you have had success migrating existing applications to Cairngorm, I'd be interested in hearing from you.


Gurufaction said...

If you want even more separation between MVC layers checkout PureMVC. http://puremvc.org

Barry B said...

documentation becoming out of date is the bane of any software. Even Adobe have to work hard with their official stuff.

and you can never have enough good documentation.

that's why the Flex community took it into their own hands to try and keep up to date.


Cairngorm withing Adobe is too small an entity to get much with official resources. Community groups are a cop-out, sure, but in the end everyone wins. The buck stopping somewhere at least...

Anonymous said...

For an even easier MVC framework for Flex check out Model-Glue:Flex at http://www.model-glue.com/

Unknown said...

Cairngorm Docs :

Includes ASDoc docs, Diagram Explorer, and examples.

Anonymous said...

I had previously looked at the Cairngorm docs website; the Diagram explorer is definitely one of the best ways for Flex coders to get up to speed with the framework. The site also has links to the Steven Webster tutorial that while very good, should really be updated. I can't help escape the impression that everyone links to it simply because there's nothing better or more up to date.

The yahoo group mentioned by Barry I had not been aware of; I'll make sure to check that out.