Model-Glue is a family of frameworks that helps developers to create Rich Internet Application easily and with less coding than other frameworks.
Model-Glue was first developed for ColdFusion, it enforces Model-View-Controller design, eases implicit invocation, does repetitive work for you, and plays well with other open-source ColdFusion frameworks.
The author of Model-Glue, Joe Rinehart, used Cairngorm for a while, then decided to write a port of Model-Glue for Flex; the goal of this project is to reach the same level of abstraction of Cairngorm without its repetitive tasks.
According to the author, this framework is:
1.Easy to understand. UI components and consumers dispatch events. Controllers listen for events and take action.
2.Streamlined. You'll write less code without sacrificing flexibility.
3.Adaptable. You can code fast and loose, catching errors at runtime, or strict and controlling, catching errors when compiling.
4.Strong but Simple. Model-Glue is based on Model View Controller and Implicit Invocation - but not at all complicated.
5.Open. All code is released under the Apache Software License 2.0, meaning that it's free to download, use, and alter.
During my researches on the web, I found a lot of enthusiastic people that have seen a dramatic improvement over Cairngorm, so I decided to look deeper into it.
Model-Glue: Flex is in an early stage of development, at the time of writing is available the alpha1 version; you can download it from the project home page: http://www.model-glue.com/flex.cfm
In the package you can find the library source and a couple of application examples; there is also a little text file with some quickstart tips. I had some problems following the documentation, probably because it is not completely in sync with the code, but I could easily create a flex library project with the framework source code. The second step was to compile the first “Hello world†application, with a button whose click is associated with a simple Alert.
The main application has a sample Panel with a Button:
<mx:Panel width="95%" height="95%" title="Model-Glue Application Template" verticalAlign="middle" horizontalAlign="center">
<mx:Button label="Say Hi!" click="new ModelGlueEvent('greeting').dispatch();" />
</mx:Panel>
The button click dispatches a ModelGlueEvent. In this application we have also a reference to the configuration:
<config:ModelGlueConfiguration />
ModelGlueConfiguration is a mxml component which contains the associations events-messages-listeners. In Caingorm we have a FrontController that associates events with commands; Model-Glue is quite different: here we have events, every event has a handler, a handler can broadcast different messages that have listeners; the code will make all clearer:
<ModelGlue xmlns="com.firemoss.modelglue.tags.*" xmlns:event="com.firemoss.modelglue.tags.event.*" xmlns:control="control.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<controllers>
<!-- A controller "listens" for messages by name. -->
<control:Controller id="controller">
<control:messageListeners>
<!-- A message listener states that a given controller method should run whenever its message is broadcast. -->
<MessageListener message="greetingRequested" method="{controller.sayHello}" />
</control:messageListeners>
</control:Controller>
</controllers>
<eventHandlers>
<!-- An event handler is an architectural event, such as a user logging in. -->
<event:Handler name="greeting">
<event:broadcasts>
<!-- A message is a statement that something has happened or that an action is needed. -->
<event:Message name="greetingRequested" />
</event:broadcasts>
</event:Handler>
</eventHandlers>
</ModelGlue>
In the <eventHandlers> section we have an event handler for the “greeting†event, dispatched on the Button click; this handler broadcasts a Message named “greetingRequestedâ€. In the <controllers> section we have a controller which includes a MessageListener; this listener associates a Message type with a controller function. So the main difference is that in Cairngorm you end up with a one to one mapping, in Model-Glue you end up with events that dispatch different events (messages), which can have different listeners; things are completely decoupled here and seem more flexible.
With regard to interaction with remote services, there are some differences too. With Cairngorm we are used to create Commands that call Business delegates, that call remote services and add a responder to this remote call. Model-Glue:Flex proposes "Autoproxies", that make a remote call similar to prototype's style of making Ajax calls; the author explains this solution here: http://www.firemoss.com/blog/index.cfm?mode=entry&entry=6F23C9CC-3048-55C9-43654A79D887EB8A
Model-Glue: Flex is a promising framework, but I cannot say that is better than Cairngorm yet, I have to play with it and above all try to use it in a medium-complex project.
Comments (1)
Isn't that the toughest thing about choosing a framework? You can't tell whether it is the right framework until you've really used it in a large project, but you can't use it in a large project until you know it's the right framework. Classic "Catch 22". :-(
Posted by Leif Wells | December 17, 2007 6:54 PM
Posted on December 17, 2007 18:54