What does Cairngorm do?
October 5, 2007
If you use Flex, then Cairngorm makes your life easier. Cairngorm makes your Flex programming more responsible, easier to maintain and extend and it promotes more efficient teamwork.
But what does it do?
Well, Cairngorm is a library (a compiled flash swf) of classes and interfaces that are plumbed together to allow the programmer to plug-in commands (control logic) and interfaces (views) in an easy, efficient manner. By using Cairngorm you are leveraging hundreds of thousands of hours of developer time figuring out what patterns work best for enterprise applications. The Adobe team used guidelines from the J2EE Enterprise Design Pattern catalog to create a very powerful framework (some say micro-architecture) for Flex distributed applications. This framework is logical so it is easy to learn and more importantly easy to teach.
Cairngorm in the work place: A trilogoy – in four parts…
Model: First off the image at left was quick effort, if it’s incorrect for some reason I will fix it (please let me know). There are 4 parts on the Flex side that you as the UI designer will have to create/modify in order to use Flex and Cairngorm to implement good MVC (the afore mentioned trilogy, work with me). To get the Model portion (session model) up and running you simply create an AS Class that extends ModelLocator. Insert data objects into this model as bindable public properties. These will drive the interface to change states, enable controls and fill forms.
View: Secondly you create the views that you need based on the model. It’s easy to test your model and views by inserting test data and manipulating it, this give you some valuable feedback on the view state relating to the model state and making sure validation is in place.
Control: Control is implemented through a multi-step process. First a user clicks a button (user gesture) which will fire a Cairngorm event through the CairngormEventBroadcaster. You must create these events, passing any information necessary for a process into one (like: new showOrdersForAccountEvent(account:Account).dispatch()). The Event is registered with the FrontController to execute a command (FrontController is a class you create that extends FrontController).
The Command Pattern is used in various ways (i.e. in java swing.Actions). In Cairngorm you implement ICommand with a class and you put your controller logic into the execute(event:CairngromEvent) method. This way an event, from anywhere in the application, can be routed by the FrontController to any Command that you want executed. The FrontController may also log or filter these events before command execution.
Thats Cairngorm MVC. There is a fourth part to getting this to work with a server and that will have to wait till another entry but first I must put some more of my old entries back up.
