May
05

Cairngorm - First Steps

What is Cairngorm and is it for me?

Actionscript seems to be a brave new world for developers; the rules are loose, the compiler is forgiving and there are many ways to get the job done. From application to application I have seen perfect object-oriented architectures, overly complex ego coding, and sloppy spaghetti code. When you are sitting down to design an application, consider existing code and design patterns. Why reinvent the wheel? The Flex architecture makes many patterns available to you and third-party frameworks (micro-architectures) are available for free.

This article and subsequent tutorials will explore Cairngorm, a micro-architecture developed by Adobe Consulting. This is a far cry from being the only or the definitive guide to Cairngorm. This article does, however, explain Cairngorm as I see it and have used it on many projects. According to the documentation, Cairngorm is an architecture based on the MMVC Model. It is specifically designed to facilitate complex state and data synchronization between the client and the server, while keeping the programming of the View layer detached from the data implementation. To me it is a set of features that fill in the blanks where the Flex platform left off.


Below is not a complete feature set, but they are the features I find most useful:

Application Organization

When starting a new Flex/Air project, the first thing I do is drop the Carngorm.swf into my lib folder and set up the following directory structure:

src
    assets
    commands
    control
    events
    model
    view
    vo    

“Assets” holds images, sounds, fonts, etc…

“Commands” holds the Cairngorm command classes.

“Control” holds the Cairngorm core classes. I usually add my delegates in here though they may be better suited in a “business” folder.

“Events” - I am going to assume you have an idea of what goes in here.

“Model” holds at least one singleton that keeps the state of the application.

“View” holds all the screens and their components.

“Vo” is used to hold value objects - simple POJOs (though this is Actionscript)

Application State

Tracking the application state in a single model is invaluable. I may be exaggerating here but it comes in handy all over the place.

Publish/Subscribe Event Model

The default event model in Flex/AIR is “bubble and capture.” The model works great until you need to send a message somewhere other than your parent. Cairngorm provides the ability to send an message from anywhere to anywhere in your application.

Discreet Commands

The commands in Cairngorm are, for the lack of a better word, awesome. They allow you, the developer, to execute specific actions based on specific events. This pattern allows you to map out your application development well before you write any code. It also raises the maintainability of your code and makes debugging easy.

Encapsulated data layer

This section of the Cairngorm framework acts like a doorway to your data source. It is possible to access http data, rtmp data and local XML all in the same application.

Conclusion

Now to the code. I hope this was a helpful and gentle introduction to the Cairngorm framework. The features outlined will soon become some of your most reliable and favorite coding tools.

Next lesson - Data Binding

Comments

There are no comments for this entry yet.

Enter a comment - moderated

Add Comment