Showing posts with label flex design pattern MVC. Show all posts
Showing posts with label flex design pattern MVC. Show all posts

Sunday, August 24, 2008

MVC with FLEX

There has been a lot of talk about flex being the next generation development tech for enterprise solutions. Whenever one gets to think about the idea of building enterprise solutions , one word can never be ignored "DESIGN PATTERNS". When you think of a MVC implementation with flex Caingorm and pureMVC frameworks are the ones all developement teams will consider.
I havent used pureMVC but worked with Cairngorm and havent felt too good with it. The problem I face with Cairngorm is that there is need to use observers to detect the change in the model. I mean the the view really has no idea when the model it consumes would change.
The problem here is when multiple UI components are trying to detect a change to the model, you have no idea about the order in which the views react. So cairngirm became a sure shot way of getting into trouble for me.

So I had to find other approaches. And a different approach find did I. :-) . Here is a brief description of my little MVC implementation.

  1. Create an interface that acts a contract between the view and the controller(handler)
2. Have the view implement the interface. This helps you create a handler that doesnt need to know much about the view that is consuming it.

Ex: -- > mx:Application implements="com.simplemvc.IsampleInterface"

3.Create a reference to the handler in the view . The handler should also hold a refernce to tghe view. Have something like

Ex:--> handler:SampleHandler id="myHandler" view="{this}" myData="{this.gridData}"



4. Call the methods in handlers/controllers when you need to .
Ex: handler.getData();

5.Have the handler call your remote Object/web service/httpservice and call back the view using the reference
Ex:view.updateCollection(data:ArrayCollection)

Checkout the source code here

Comments welcome.