Thoughts on Presentation Patterns

It’s great to see more and more enterprise Flex applications being built. However, as the scale and complexity of these applications increase so the design challenges we face.

One problem area is the presentation layer where a plethora of design patterns exist. Paul Williams produced a good series of “blog”: posts on presentation models and there is a good “document”: from Martin Hunter on MVC, MVP and MVPC. Even with these patterns we still face design challenges if we want to write clean code that is easy to read and stands up to change.

One challenge is messaging between view components. I have seen various solutions and nearly all are based on events. Lets diverge for a bit. Events are a core part of the Flash/Flex programming model and they rightfully have their place, but on the other-hand they are a menace to clean code. As apps scale I have seen too much code polluted with event handling, which obstructs readability. The big problem is the execution path, when the event is fired where does it go? Who is handling it? As the app continues to grow it becomes easier and easier to simply listen for events, the result is we rapidly loose our mental picture of how the code is executing. We often justify this as loose coupling, which I would argue against. I am a proponent of loose coupling, but I want to be able to look at the code and read through the execution path. Tooling is making it easier, but it doesn’t change the fact that the code is no longer readable.

Coming back round to presentation patterns, the other problem I see is an overuse of patterns. Especially within the presentation layer. It seems to be more and more common to combine presentation patterns, giving each their own subtle responsibility. Not only does it detract from the readability but it also confuses new engineers to the project. How do you explain their subtle responsibilities? If you can’t clearly articulate your vision then the design will soon erode and you will be left with a rotten codebase, which is difficult to maintain and extend.

Now I don’t see a silver bullet to these problems, but I would like to suggest an alternative. This emerged from a Pair Programming session with one of my colleagues, Dan Harfleet, who deserves the credit for this approach. We were using the Presentation Model pattern to separate the graphics aspect of the view from its behavior and state. We were using a Panel, which was composed of a couple of view components, each with their own Presentation Model. The main Presentation Model for the Panel was responsible for updating the Panel’s status, but we wanted the nested components to also update the status. How do the Presentation Models communicate?

We wanted to avoid dispatching events and we wanted to avoid using a mediator for the reasons given above. We decided to take a simpler approach, which is based on the Observer pattern. Although it increases coupling, it introduces an explicit contract and allows us to easily read the code execution.

We started by creating two interfaces:


public interface StatusReceiver
function setStatus( message : String ) : void;


public interface StatusNotifier
function addReceiver( receiver : StatusReceiver ) : void;

The main Presentation Model implemented StatusReceiver and all other Presentation Models implemented the StatusNotifier. The attached sample application, which is over simplified, is using "Parsley": All Presentation Models are declared on the Parsley container. On the concrete implementation of StatusNotifier we decorate addReceiver() with the [Inject] metadata tag and Parsley injects the StatusReceiver.

I found this to be a simple solution. The two interfaces form a clear and concise contract and without using events I can easily read the code and understand what is happening.

Downland the sample "here": and give it a try. I would interested to here your thoughts.

Sneak Peak at Cairngorm Persistence Library

For a while now I have been working on a ORM library for AIR and SQLite. It’s not officially launched yet, but if you want to sneak a peak and give it try then look “here”:

I took my initial inspiration from “iBATIS”: as I wanted the developer to have control over the SQL. It is intended to be incredibly simple. You put the SQL in a SQLMap and then decorate your VOs with metadata. There’s a sample app so take a look and let me know how you get on.

Cairngorm Plugin Available

The Cairngorm Plugin is now available as a public beta on Please click here for details on how to install the plugin.

I am looking for people to join the Cairngorm Plugin project team, if you are interested please email at


Cairngorm Plugin @ MAX

The Cairngorm Plugin has now been launched internally within Adobe Consulting (AC) as a private beta. Eric Garza and myself will be formally launching it as a public beta at our MAX talk.

We also have a cool looking splash screen for the plugin, which was designed by George Neill of AC along with all the other icons (and I thought George was just lazy :)).


In the run up to MAX I will try and blog some more details about the plugin and some up-to-date screens shots, as it has moved on since my earlier sneak peek.

Cairngorm Plugin Sneak Peek

This is very much work in progress, but I thought it was about time I shared my work on the Cairngorm Plugin. At the very least this blog post is intended to give myself a kick to get it finished! I would like to release a Beta version in the next couple of months.

The intention of the first release is to focus on the Front Controller and simplify the addition of new CairngormEvents and their corresponding Commands.

In the mean time I would like to provide some detail on what I have done so far and describe some of my ideas. In the whole the plugin is complete, I have all the moving parts, I just need to bring them together.

Continue reading…

*New* FlexAntTask – fails build if test suite doesn’t execute

The FlexAntTask will now fail the build if there is an error executing the test suite e.g. a socket timeout. In the past the error was swallowed as the server socket runs in a separate thread – any errors are now passed back to the task and re-thrown.

Binary distribution


Source Distribution


Example Project


Ant Task Parameters

swf The name of SWF containing the tests to execute. Yes
port The port to receive the test results on from FlexUnit. The default port is 1024. No
timeout The time in milliseconds to wait for results from FlexUnit before stopping the building process. The default is 60 seconds. You need to allow enought time for your tests to run as the socket is opended prior to the test execution. No
toDir The output directory for the test resutlts. The default is the working directory. No
haltonfailure Stop the build process if a test fails. The default is true. No
failureproperty The name of the property to set in the event of a failure. The default is ‘flexunit.failed”. No
verbose Causes the flexunit tasks to print status messages. The default is false. No

Delivery of a Mission-Critical RIA for NATO

At MAX 2008 North America I will co-presenting Delivery of a Mission-Critical RIA for NATO with Mansour Raad of ESRI.

We will presenting on Tuesday @ 4:30PM in Moscone West 2011 so come along and see us.

The session will take a look at a mission critical application developed for the NATO E-3a Component to plan missions flown by their AWAC aircraft.

The MSS application has been developed using Flex 3 and LiveCycle Data Services and makes heavy use of Data Management Services, which enables users to collaborate on mission planning.

A key element of the MSS application is the world map, which allows users to visualize and work with geo-spatial data. The map has been developed using ESRI’s AWX Flex API. The map is driven using managed data so a change to a geo object is immediately pushed to all users currently working with that geo object!

During the session will take an extensive look at the application and how it has been engineered using AWX and LiveCycle Data Services.

Scotch on the Rocks: Introduction to Data Mangement

Today I spoke at Scotch on the Rocks. My presentation provided an introduction to Data Management. You can download my slides from here and the demo app from here.

The demo provides 5 applications:

Main – vanilla DataMangement application – it doesn’t get any simpler than this 🙂
Main1 – adds autoCommit=”false” and revertChanges()
Main2 – adds createItem()
Main3 – adds deleteItem()
Main4 – adds conflict handling

Thanks to everyone who attended.

FlexUnit for Ant now supports Mac OS X

A big thank you to Tom Sugden who has added support for Mac OS X.

For more details on how to use FlexUnit for Ant please see my earlier blog. There is also documentation on the flexunit Ant task parameters at the end of this blog. You can download FlexUnit from Adobe Labs.

Continue reading…

MAXchalking on Client-side Data Modelling in Flex with Data Management Services

At MAX myself an Tom Sugden will be doing a "chalk-and-talk" session. The "chalking" will last for 10-20 minutes. During this time we hope to bang a few heads together to help us answer three questions we have with the design of our client-side model.

We will start by providing you with some context, not much mind you as the clock is ticking. We will quickly move to draw up our design pattern for the managed-model and talk you through the problems it solves.