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.

6 comments:

Brijesh Bolar said...

Hey Venkat,

The examples area is blank in the blog.

Vengu said...

Hi Brijesh,

I am able to download the zip..

May be you should disable your popup blocker..

Thanks,
Venkat

Vengu said...

OMG! Blogger doesn tlike mxml tags it seems..

Brijesh Bolar said...

Yeah Buddy...

M facing the same issues while posting code in my blog..

Do you have idea how to put code in ur blog.. with mxml tags ofcourse.

It its a normal code it works fine. But at times I'd want the color coding format also to come.

Let me know if you come across any info on this.

Anonymous said...

dude ur pic sucks-lavanya

Vengu said...

@Lavanya-Mind sending me yours? :D