开发者

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

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


Personally, I think the easiest way to deal with this situation is to inject the Model directly into the View (via a constructor, or other mechanism).

Simple, yet effective.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜