27 Aug in flex, mate

When I first wrote about Mate vs Cairngorm, the main concern I stated with both was that in any MVC architecture there's little consideration given to splitting out the data/business code from the presentation code. In custom, one-off projects this is rarely a problem. However, when you're writing several different frontend apps that all use the same backend and data it's frustrating to have to duplicate that data/business code.
I'm happy to say that I have overcome this concern with Mate. I'm not too familiar with Cairngorm yet, but I believe a similar method would also work.
In a standard Mate application, your event map makes the calls to the server, a manager manipulates the data and your model stores that data. Your view then binds to the model to display the data as it wishes.
The beauty of this is that you can easily add another component, known as the model adapter. This sits in between the manager and the view to mold the data into the correct format for your presentation layer.
Basically, the manager pushes the "raw" unmodified data from the server into the model. The model adapter sits within the presentation layer and takes the data from the manager, manipulates it in a custom way for the view and allows the view to bind to it (or injects the data from the adapter directly into the view, depending how your system works). The injection & bindings are configured in another event map that again sits within the presentation layer.
As an example, consider a server call that returns a small list of users. Your backend project will ultimately store an array of User DTOs. However, if your frontend project requires to list the users from a Menubar control, you would have an event map in the frontend that binds the User array to the model adapter (also in the frontend). Your model adapter would then create an XML object containing the correct data for the menu and inject it into the menu view.
When I get change I'll get a diagram up of the above jargon to hopefully make it a little clearer!
UPDATE: A former colleague, Alex Rosano, has posted a Cairngorm version of this concept on his blog. Head over and check it out: http://alexrosano.com/flex/cairngorm/abstracting-services/

Comments

Diagram and example code maybe?

"When I get change I'll get a diagram up of the above jargon..."

How is that coming along? And do you think that you have time to add a small example of that implementation?

Thanks, Greg

Sorry for taking so long to

Sorry for taking so long to get this together. Here it is:

http://blog.preinvent.com/node/12

All content © 2009-2011 Matthew Butt. All views expressed herein are my own and do not represent the views of my employer, AREA203 Digital.