Monday, May 21, 2007

Cairngorm: Cares are gone?

The last couple of days I've been playing with Cairngorm. It's a "microarchitecture" framework from Adobe for developing enterprise level Flex applications. (If you develop web applications, desktop applications (checkout Apollo), or are looking for an easy way to put a front end on some software and haven't fiddled with Flex yet, you should definitely check it out.) After I rewrote some code using Cairngorm I compared it with the old code. There was much less code and more classes but the code was much cleaner and better organized. My initial impressions were good.

There is one thing that I haven't discovered how to do well in the Cairngorm framework: how to manipulate the view in more compilcated manners. For example, we have a login window that we implemented using PopupManager - it provides modality, grays out the background nicely, etc. But how should the model notify the view to remove the login window? The best I could find was the Observe tag by Alex Uhlmann (download) which allows you to "observe" a piece of data by binding to it and executing a function when the data changes.
What to do when the data hasn't changed though? Let's say I have the property

[Bindable]
public var isAuthenticated:Boolean = false;

in the data model. The problem is: what if the user actually failed the authentication? Setting this property to false will not update the view (no change occurred). I need a "tri-state" Boolean... yeah that's it! I'll call it a troolean. (Just kidding, don't email me about a "troolean".)

I thought about having the commands call a function in the view to take care of it directly, but then I realized that it defeats the point of the architecture. It makes the view and the commands too tightly coupled. What if the login window isn't being displayed or isn't set to a reference (it was implemented as a pop up, remember)?

I finally settled on letting the command display an alert to the user, so I didn't have to worry about it. If anyone has a better way of handling these types of scenarios, please let me know.

In the meantime, I think this framework is a huge step forward in my thinking about event driven architectures. But I don't think it's solved all my problems yet.

No comments: