Good Tips When Using Cairngorm in Flex Applications

Cairngorm is a useful micro architecture for Flex. Its a basic framework on building applications. Many of you have adopted Cairngorm and given it a try in your apps. Here are some useful tips that could help aid in your development.

Constants

Create a constants folder in your apps package contents under com.companyname.applicationname.constants. This folder will hold all your constants in your application. This doesn’t include any event constants, keep those in your event classes. We are talking about your media library, application states, and so forth. This is also a good spot to insert any other specific states you want to implement in your application as well.

Don’t Be Shy About Building Commands

Create as many commands as you see fit. Sometimes building a Cairngorm based application, it feels like putting a engine together but you are missing parts. Create commands for the simplest of operations and give good names. For instance, if you want to run a ’save’ function, it would be good practice to have these commands, InitializeSaveDocumentCommand, DoSaveDocumentCommand, and IsFinishedSaveDocumentCommand. We could event branch these out further if need be. It might seem overkill but in the end, in a large application, this could come handy. Its nice to call events in the similar fashion where the event calling those commands would be called SaveDocumentEvent.

Command Organization

There will be many a commands created in a standard Cairngorm application. Twenty to thirty is common, but some could reach over 100 and beyond. The com.companyname.applicationname.commands folder can become a monster. A good way to manage this is to sub folder into Events that drive them. That way your SaveDocument commands would end up in com.companyname.applicationname.commands.savedocument.* .

Data Transfer Objects

I like to use the term DTO( data transfer objects ) more than value objects. Therefore I like to rename my vo folder to dto. Create and extend many of these objects as they will help you code complete in Flex Builder and overall get organized.

Other Hints

Use short cuts where you can. Here is a few that I can’t live without:

  • ctrl-space - use this for code complete, a must. This is particularly useful when getting your model locator or long command names.
  • (apple or ctrl)-mouse click - this will being you to the source code of the class you clicked on in the Flex Builder IDE. Unfortunately this doe not work for compiled code
  • shift-(apple or ctrl)-c - this will comment any code that you have hi-lighted

Happy coding Flex developers.

Links in this article

Cairngorm

Share this:
  • Digg
  • Facebook
  • Google
  • del.icio.us
  • Mixx
  • StumbleUpon
  • LinkedIn

Leave a Reply