Archive for June, 2009
I was doing a technical interview the other day and I got a question that really threw me. The question, if I remember it correctly, was "What are the mappings in either Cairngorm and/or PureMVC?" What threw me was the word "mapping". So off I go to Google to try to find the answer…
For PureMVC I found the word "mapping" being used in an FAQ post describing a best practice for listing out constants that map the commands/notifications for the application.
http://puremvc.org/content/view/93/188/
Just to highlight a point the FAQ post makes, it’s what to do with all the constants that would be created with a larger application. I have created a couple of apps where we would have 50+ constants defined in the ApplicationFacade that would then clutter up the code and make it harder to search out issues in the code. My recommendation is for all PureMVC applications to have its constants in a separate file (ie: AppConstants or something to that effect) for defining all the constants for the app. This allows comments with the constants as well as the option to organize them to the same flow as the UML or storyboards. In an agile development environment it is imperative that code be well organized to provide the ability locate and change aspects of the application at a faster rate. Having the ability to search one file and then allow the Flex IDE to search out uses of the definitions makes debugging issues less of a choir.
For Cairngorm I felt the word "mapping" had the same meaning as it would for PureMVC but implemented in a different way. Cairngorm uses a process of mapping Commands to Events and is done within the Controller file. I have seen developers separate out the Event name constants into it’s own file and then importing the file into all the individual event scripts. Another way, is to simply define the constant(s) name within the Event itself and make the constant name the same as the Event name and file name. Keeping everything named consistently makes searching an issue or change easier to do. Again, since the event files define their constant names within themselves, I name the file the same as to what the constant name would be for the Event. Keep the name descriptive as to what the Event is meant to accomplish.
The following link to to the Cairngorm introduction:
http://www.adobe.com/devnet/flex/articles/introducing_cairngorm/introducing_cairngorm.pdf
In the end I am sure there are several other ways to "mapping" your processes and constants out in your Flex applications using the above micro frameworks. A word of advice is to create a process and stick with it. Keeping your code organized and commented is key to adding value behind your coding work. If the code is unmaintainable then its garbage.