R – is creating the model as a singleton the only way to share data in the mode between views

apache-flexmodel-view-controller

I'm creating a MVC base application, in the past I've alwaysed use Cairngorm as the framework for my Flex applications. For this app I'm experimenting with other approaches to mvc, not other frameworks (pureMVC or Mate), but writing my own MVC base application.

My question is in Cairngorm I've always created the model as a singleton, but what ways can I pass data from the model to the view and not use a singleton.

I was thinking of injecting the model into views or is another approach sending events containing data to and from the model to the view via the controller?

Thanks

Stephen

Best Answer

I would declare the data as public properties. You almost always need to update data in a View based on user gestures, so using constructor arguments alone isn't very flexible and can be problematic for MXML-based Views.

Then you can either use binding expressions in the parent View to supply the data or use an IoC framework such as Swiz or Mate to inject the data. The disadvantage to the former approach is that you end up putting a lot of public properties in your parent views just so they can "relay" data to the child views. The nice thing about IoC is that you can add only the properties each View actually uses and then inject the data only where it's really needed.

Related Topic