Being a Java developer I felt that Cairngorm was a God sent as it provided me with a familiar way of constructing an application architecture. This made the process of starting developing in Flex a lot less complicated than if I where to start from scratch. In my old company Ezmo we built an online music service using the Cairngorm framework. We where very happy in the beginning and we really felt that Cairngorm helped us a lot as we didn’t have to learn too much about the inner workings of Flex and Action Script in order to start shipping working software.
As we continued growing our application I could not help to notice that there really was a few things about the framework that really started to degrade the quality of our code base and really made our application harder to maintain.
Writing a Cairngorm application involves a lot of boilerplate code. In order to get just a simple command going you need to create 2/3 new classes and write 20/30 lines of code which provides no value what so ever.
I really feel the Cairngorm framework should try and encapsulate more of the inner workings and hence saving developers a lot of time and effort. When designing a framework I feel you should have the approach the guys developing Spring Framework for Java has: to make development simpler. Cairngorm does not make development simpler and as your application grows Cairngorm really starts to slow you down.
Numerous studies has shown that the more lines of code you have in your application, the higher is the potential for bugs. Therefor it would be beneficial for an application framework such as Cairngorm to let developers write less code. In my experience Cairngorm does quite the oposite. I have compared an application created using Cairngorm to the same application written from scratch with a custom architecture and Cairngorm adds numerous classes and several hundred lines of code (I’ll provide samples of this later on).
When I work with Cairngorm I get the same feeling as I did back when I had to work with EJB 2.0. It feels like a plastic bag that’s constantly over your head while you try do develop your application. The framework is intrusive and continues to force you to write tons of useless code and transforms all applications intro dinosaurs that become hard to maintain and really hard for new people to learn. Regardless of all the patterns used in Cairngorm, it is not easy for new developers to start developing when they have to related to such a huge number of classes.
In my experience most applications don’t need to implement the Model Control View pattern in order to provide a decent application architecture. Especially I feel this is the case for Flex, you really don’t want to mimic a Java web application when you have such a great framework as Flex!
Listen Adobe Consulting, either you try and upgrade your framework to something that fulfills the demands of developers in 2008 or you release it as Open Source. Right now all the new things in Caringorm are related to their ridiculously expensive Live Cycle Data Service, nothing in regards to making development faster and easier. If you don’t have the time or resources to do this, release it and maybe the community can help out (I am fully aware that I should put my money where my mouth is and develop my own framework, but this is not something I have time to do right now).
Having put down the Cairngorm framework I guess you want to know what to do? OK, I’ll try and elaborate some of my thought on how you best construct and application architecture in Flex.
There are two valuable things in Cairngorm which I would continue to use (but I would probably just develop those classes my self for each project):
All the command, event, front controller mumbo jumbo is just there for the pattern horny architects who does no actual coding and have a need to have as many patterns as possible in every application architecture the work on.
Now here is why I feel these things make sense for almost any project. The Model Locator pattern, as Adobe calls it, is a great way to control data in your application. Combining the Model Locator with the built in feature of data binding in Flex that is a really powerful combo. If you combine this with a Business Delegate class you have pretty much all you need (you may not actually need that class either, it is not very hard to write one on your own).
If you decide to throw out most of Cairngorm and write your own architecture I would advice you to use two types of Models: Presentations Model and Server Models.
Having a one-to-one relation between the server side services and Server Models provides you with a seperation between server side data and the presentation data. Server Models should be responsible for retrieving their own data (that’s right, no events/commands needed). Presentation Models can use one or more Server Models, and once again using data binding to control updates. I think this provides a really simple, but yet very scalable, application architecture.
I am terribly sorry about the mistake of not remembering that Cairngorm is Open Source. Since I wrote this I have been notified about some other articles dealing with the same issue and I think the best one yet is an article called Using Cairngorm & Thoughts On Handling Those Pesky Singletons
.
Subscribe to comments feed (this is global, not just for this entry)
Being accustomed to the development tools for Java development it has been really frustrating to move into the world of Flex and Action Script with it’s immature IDE’s. However it seems as if this is finally getting attention at Adobe and the Open Source project FlexPMD is really becoming a great tool for assuring quality [...]
I have for some time been running Ubuntu on my work-at-home-computer. Having to work with Flex on Linux is a constant struggel and I can understand why most people would just give up. I can see that the number of Flex developers on Linux is quite small, however I think it’s a shame that we’re [...]
One of the most challenging tasks when being architect on a large project is to keep some kind of track on what developers are doing while you are wasting away time in planning meetings and all other kinds of useless management activities. In the Flex echo system there are very few tools which help you [...]
Couldn’t agree with you more.
Although as far as I know Cairngorm is open source.
MVC is only cool if you like dictatorship.
Controller == Dictator
You don’t want to live in a Dictatorship so why would you want to code one?
Controller is an OOP Anti-Pattern anyway.
April 25th, 2008 at 10:30 pmBesides that, Cairngorm was created for only one reason.
To draw attention to the guys at Iteration Two so they could make more money.
If you are curious how well it worked, then ask the guys at Adobe Consulting (formerly Iteration Two) how much their Adobe stock is worth these days.
When Cairngorm was first released Flex Engineers from Macromedia advised against using it citing ‘Anti-Pattern’.
April 25th, 2008 at 10:35 pmno doubt Cairngorm has served it’s purpose for it’s authors, there’s no denying that
I don’t think Cairngorm is Open Source, they’ve just made the source available. At least I’m unaware that you can contribute into the project.
Anyway, I was just writing this as an advice to those starting out with Flex that they might be just as well off going on their own.
April 25th, 2008 at 11:20 pmAny of you used PureMVC? Is it any better?
May 13th, 2008 at 7:23 pmHi Daniel,
I have not used PureMVC in an actual project, but I have studied the documentation and I feel it suffers from a obsession with patterns without there being a need for all of them.
PureMVC is a generic framework which is ported to ActionScript, which means that it lacks support for key Flex features such as Data Binding. In my book this makes the framework not worth using as this is a feature which makes Flex so amazing to work with.
Instead of Data Binding PureMVC uses a set of patterns to achieve the same thing, but I really feel that PureMVC is a dead end. But please, if this is totally wrong I’d be happy to eat my own words
May 13th, 2008 at 8:01 pmCairngorm is bad, PureMVC is bad.. Is there any other good framework besides them?
May 14th, 2008 at 7:30 pmCairngorm isn’t all bad, like I mentioned I used it as a crutch when I started learning Flex.
but I think once you’ve learned basic Flex and built a application in Cairngorm you will profit from just building your own architecture.
what is difficult in Flex is not retrieving serverside data and stuff like that, it’s more related to UI work. so I think just don’t focusing that much on frameworks allows you to work with what’ll be a challenge: the user interaction.
May 14th, 2008 at 8:37 pm> Any of you used PureMVC? Is it any better?
I use both Cairngorm and PureMVC – Cairngrom with Flex and PureMVC with FlashCS3.
Pure MVC is similar to Caringorm, but uses more classes. There’s more to learn with PureMVC.
Both PureMVC and Cairngorm are excellent PRO quality frameworks.
You have to understand that while there is a certain amount of code to write when using either of these frameworks, you only write it once and reuse and reuse and reuse it.
It takes me around 20 minutes to set up a project for either Cairngorm or PureMVC. The time you spend doing that will reap huge benefits as you go along.
Say what you like about MVC, but for anyone reading this who is thinking about using these frameworks, you should realise that MVC is used everywhere, by everyone throughout the software industry. From computer games, to spreadsheets, to music sequencers, to accounting software, to air traffic control, to NASA.
Using MVC is not only about the time it takes to write software. It’s also about maintenance. If you use MVC properly, maintaining your application will become an order of magnitude faster and you will be able to make radical changes to your code without breaking it.
Both Cairngorm and PureMVC are pro quality frameworks. They are not for the faint of heart. It may take you a little longer to get started with an app, but you will speed ahead.
I laughed when I read this article. For example:
> I could not help to notice that
> there really was a few things
> about the framework that
> really started to degrade the
> quality of our code base and
> really made our application
> harder to maintain.
With millions of the best programmers in the world using MVC, I won’t be the only one wondering about the competency of programmers who manage to get into a maintenance mess when using an architecture that is designed to cure that scenario.
This one really made me laugh:
> you really don’t want to mimic
> a Java web application when
> you have such a great
> framework as Flex!
Flex isn’t an architectural framework. There is no comparison. LOL. MVC wasn’t created for Java or the web. It is platform and language agnostic. The Java world uses it because it works, just as the rest of the world uses it because it works.
All development on Apple computers, from the mac to the iPhone is done using MVC. It’s built into the entire process – the libraries and all development tools. Everything is MVC on a mac. MVC permeates the entire world of software, from mainframes, to the desktop and the web.
May 18th, 2008 at 3:24 am> I have not used PureMVC
> in an actual project, but
> I have studied the
> documentation and I feel it
> suffers from a obsession with
> patterns without there being a
> need for all of them.
The reason that Cairngorm and PureMVC use several patterns and classes is because each and every thing is reuseable. They are both designed so that each and every bit of code you write, does one thing and you never have to write it again or maintain it in multiple places. So, while it takes a bit longer to write it the first time, you will never have to do it again.
You write the code that gets the data from a service, and you can reuse it with other commands that do different things with the code. Simple. There is most definitely a need for all the patterns. The people who wrote these frameworks knew exactly what they were doing.
> PureMVC is a generic
> framework which is ported to
> ActionScript
Actually, PureMVC was not ported to Actionscript. It was written specifically for Actionscript and ported everywhere else.
> which means that it lacks
> support for key Flex features
> such as Data Binding.
Consider this. Many developers work with both Flex and Flash CS3 and Actionscript AS2 and AS3. I’m sure they’d love to work purely in Flex / AS3 all the time, but the commercial world isn’t like that. Sometimes they have to do whatever is already there.
Flash CS3 does not support data binding. Flex does not support AS2, yet PureMVC supports them all. Developers can use PureMVC across all their projects and on the server using PHP. One framework to rule them all. There is no other framework that does that.
As far as data-binding goes, it isn’t as much of a loss as you would think.
> In my book this makes the
> framework not worth using
The fact that PureMVC is generic, was a masterstroke on the part of the designer.
May 18th, 2008 at 3:47 amIn addition to my comments below, note the following about PureMVC and databingding:
Daniel said:
> [PureMVC] …lacks support
> for key Flex features such
> as Data Binding. In my
> book this makes the
> framework not worth using
> as this is a feature which
> makes Flex so amazing to
> work with.
Cairngorm doesn’t ’support’ data binding either. Well, not as such. Data binding is a built in feature of Flex. Cairngorm simply doesn’t provide another mechanism for getting the data to you.
Using PureMVC doesn’t make the Flex data binding stop working. It’s still there and you can use it. What PureMVC does do, is to provide extra features so that it can be used in other Actionscript environments that don’t support data binding, such as FlashCS3.
You can use Cairngorm outside flex, but you will have to come up with your own mechanisms to replace data binding. With PureMVC, it is all already there.
PureMVC does support data binding. Anything in Flex supports data binding. You can’t switch it off. If you want to use it, there it is.
May 18th, 2008 at 4:05 amHi James, I am glad you fond the posting entertaining
However I think you are somehow missing my point, I am not saying the MVC pattern is bad. Like you say this is a tried and tested way of creating applications.
I complain about Cairngorms implementation of the MVC pattern and how it really does not aid developers. I think largely Cairngorms problems are there because it’s an old framework. A few years back in Java you had the old Struts framework and Web Work. Everyone rightfully complained about Struts and the fact it was old and filled with hassles. Whereas the new kid on the block, Web Work, was brilliant and really helped speed up development. I feel the Flex world is at this spot right now, only that there is no WebWork out there yet.
Cairngorm as a framework makes you have to write too much code. More code, more potential for bugs. Secondly Cairngorm based applications are a bit too complicated to unit test which is also a very important aspect of what you call “Pro frameworks”. Cairngorm solves some issues new developers may struggle with, but it makes your code base become bloated with event and command classes. In addition it really doesn’t have any good solution for more complex asynchronous operations such as a batch or requests for web service (I know about the sequence command, but that’s a horrible solution).
I think your points about PureMVC and it’s use in Flash are very good points and obviously I’m not a Flash developer so I guess my comment was a bit off due to lack of knowledge.
May 18th, 2008 at 1:30 pmPlease see recent post to http://weblogs.macromedia.com/swebste r- Cairngorm will be moving to opensource.adobe.com in the very near future, in order that we can more easily accept community contributions. In addition, there are other Adobe Consulting blogs (and presentations such as Flex 360 and MAX) where we’ve also shared our views on presentation model patterns alongside (not instead of) Cairngorm. We endeavour to publish more around how we use Cairngorm in the near future.
May 26th, 2008 at 8:29 pmJames
Maybe you should re-read the article. This is about cairngorm not MVC. Just because i think a Pontiac Aztec (Cairngorm) is a pos, doesn’t mean i have a problem with cars (MVC).
Try writing test case classes for a large application using Cairngorm, then tell me what you think about it.
July 22nd, 2009 at 11:24 pmnice post
100% agree with this. ive checked both PureMVC and cairgorm – and i was left with conclusion – both lead to serious code bloat, that makes the project unwieldy to navigate as the the number of classes increases quickly more code = more testing. theres better ways to implement MVC than using this strict approach imo (check Danny Patterson’s book on AS3 Design Patterns for one).having said that if youre using continuous integration and maven there’s a lot of power in cairgorm if u dont mind a serious investment in time and effort. I would love to hear a case for Facade pattern in AS3 if anyone knows.
October 14th, 2009 at 7:58 am