PDA

View Full Version : Flex MVC best practices


preslavrachev
03-21-2009, 02:38 PM
Hello everyone,
I would really like to know what the best practices to implement MVC in Flex currently are. Imagine that we have a complex application that has MVC applied not only on the application level, but also on the component level, i.e. every custom component represents an MVC architecture as well. How will you tackle that? How will you design the communication flow? Would you use a Singleton model whose instance you will get on every level, or you will use multiple model instances? How will you make component controllers "speak" to the application controller? Will you add event listeners in the app controler, or will leave the MXML containers responsible for arranging that?


Please, toss in any suggestions that might come to your head.

Peter Cowling
03-21-2009, 04:55 PM
How will you design the communication flow? Would you use a Singleton model whose instance you will get on every level, or you will use multiple model instances?


In cairngorm you use component level models. In pureMVC, you work with a facade - which provides access to all MVC actors.

How will you make component controllers "speak" to the application controller? Will you add event listeners in the app controler, or will leave the MXML containers responsible for arranging that?

In Cairngorm you have the controller as a direct intermediary of the events and the commands. (So you import and call event classes, register all events and their command equivalent in the controller, and build out the commands.) PureMVC is similar: Notifications are called from the view, and being passed to the controller via an Observer.

You can use other frameworks, including your own, and choose to use other design patterns, but it is my view that the choices are less concrete when it comes to models, and more so with regards to the trigger -> controller -> command part.

mattb
03-25-2009, 01:43 PM
Also have a look at the Mate framework: http://mate.asfusion.com.

Mate uses an EventMap as the controller that basically deals with handling events and moving data around. For per-component MVC implementation Mate has a LocalEventMap which is identical to the EventMap except it only listens to events fired from a particular dispatcher isntead of at the application level.