Cairngorm Getting Started Part One : Overview
Thursday, 19. June 2008 21:58
First things first I need to acknowledge David Tucker for this fantastic post that got me started.
As David Tucker says in his post, though I think he’s lying, I’m no Cairngorm Expert either. But I have used it recently and I like it. What I’m doing with this post is to explain it as I get it, so if I’ve made any glaring errors please let me know. This is also an aide memoir to myself too so I apologise for the slightly jovial tone, I like to keep myself amused while I’m writing. What I can say with authority though is that I really like Cairngorm even though I’m currently using the PureMVC framework (I hope to post a similar getting started for that framework).
The Cairngorm framework appears to be the main framework suggested by Adobe for use when creating RIAs with Flex. There are lots of other frameworks, Pure MVC being one of them, but this one is really being pushed as they bought the company that created it (Iteration II – acutally they were bought by Macromedia, who were then bought by Adobe, but the essential theory stands).
Cairngorm is an MVC (Model, View, Controller) framework that aims to seperate these different parts of an application so it is easy to maintain and also easier for large development teams to work on. As each part of the application is seperate a different developer can work on each bit, after planning the application of course.
In essence with an MVC design pattern the Model should deal with the data, the Controller with telling the Model what to do and the View should site there happily being told by the model what it’s supposed to be display.
I’ll have a go at some pretty diagrams of the MVC pattern (you’ll see I’m no designer) but I’ll mainly explain the way I understand it.
At the most simple level : -
A user interacts with the view. The view dispatches an event which is mapped to the controller (known as a command), the command makes a change in the model and the model then tells the view what to display.
Now this is all well and good, but really the whole point of framework is to make it easy to manage the application and that includes data connections. So the next step is : -
A user interacts with the view. The view dispatches an event which is mapped to the controller (command). The command creates a delegate to make a call to a data source and a responder that the result from the data call is mapped to. The responder makes a change to model (which it is allowed to do as it is a controller) and the model tells the view what to display.
So for a simple app that loads some XML the flow would be : -
- Application Inititialises
- Dispatches an “I’m alive” event to a controller class
- The controller class creates a “GetXMLDelegate” class that calls to load the XML
- The XML is delivered back to responder (at the control level)
- The responder changes the model
- The view displays the data the model holds
OK, OK, I’m laboring the point – but that sort of is the point. It seems very obvious but this is really important. View talks to Control, Control changes the model, model gets the view to display what it tells it to.
The most important and cardinal rule is ONLY CONTROLLERS (ie. Commands or Responders) CAN CHANGE THE MODEL! If you stick to this cardinal rule your life with Cairngorm will be much more fruitful.
One other bit of advice is to try and keep things simple. One command does one function. This means you’ll end up with loads of classes, but if something does go tits up then you’ll probably have a good idea as to exactly where the application is failing, and probably the filename of the class that is the problem.
OK – part 2 – lets set up the environment for developing with Cairngorm.
Category:Cairngorm, Flex, Flex Builder, Frameworks, Tutorials | Comments (1) | Author: admin




















