关于双目标环境中MVVM的问题 [英] Questions on MVVM in dual target environment

查看:66
本文介绍了关于双目标环境中MVVM的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨社区,



我的团队讨论中提出了这些问题。我想收集社区对这些观点的反馈。 (图例:V:视图,VM:ViewModel,M:模型,IM:ViewModel的界面,INPC:INotifyPropertyChanged)



1. VM是否应该与M无关?

2.当我们说V期望来自VM的一组属性时,V和VM是否紧密耦合?

3.在VM中传递M或(IM)是否可以构造函数,以便在双目标场景中,M for Desktop可以替换为M的Silverlight而无需更改VM?

4.可以假设在双目标环境中我们更有可能拥有不同的M for Desktop和silverlight吗?或者我们应该努力拥有相同的M但不同的VM?

5.总是假设桌面和Silverlight的V会有所不同吗?

6.是不是如果我们努力寻找一个只有getter和setter属性的普通虚拟机,那就更正了。我们创建一个抽象b / w M和VM让我们说A.我们的A将监听M中的变化并在VM中设置属性。同样A将订阅VM的INPC,并更改M.通过这种方式,我们将有一个可以在Blend中使用的VM。此外,我们的VM对于Desktop和Silverlight将保持相同,因此我们可以将此VM打包到一个独立的库(dll)中。该库将是一个公共访问点。因此桌面和Silverlight的公共API保持不变。





请注意,在一段时间内,许多不同的MVVM概念已经发展为最佳实践。所以我的假设可能与你的假设相矛盾。请随意提供一些例子,因为我非常乐意改变我的假设/意见。



提前致谢:)

解决方案
1。不会。这听起来你并不完全了解模型是什么,而你似乎认为模型只是数据实体。事实并非如此 - 这是一种常见的误解,因为人们认为MVVM纯粹是一种表现形式。它不是,它是一种架构模式,所以模型不只是引用数据实体,而是与视图/视图模型所依赖的服务相关。

2.是的,视图是耦合的查看模型。

3.请参阅我对第1点的回答。我希望将服务等注入构造函数,或通过属性注入注入。

为什么?如果VM不需要在两种环境中都无法获得的任何东西,为什么它们会有所不同。

5.否。

6.不。不应该是你的目标。


Hi Community,

I have these question that came up in my team discussion. I wanted to gather community's feedback on these points. (Legend: V: View, VM: ViewModel, M: Model, IM: interface for ViewModel, INPC: INotifyPropertyChanged)

1. Should VM be agnostic of M?
2. Are V and VM tightly coupled when we say V expects a set of properties from VM?
3. Is it fine to pass M or(IM) inside VM constructor, so that in dual target scenario an M for Desktop can be replaced with that M of silverlight without changing VM?
4. Is it fine to assume that in dual target environment we are more likely to have different M for Desktop and silverlight? Or should we strive to have same M but different VM?
5. Is it correct to always assume that V would be different for Desktop and Silverlight?
6. Is it correct if we strive for a plain VM which just have some properties with getter and setters. And we create an abstraction b/w M and VM lets say A. Our A will listen to changes in M and set the properties in VM. And similarly A will subscribe to INPC of VM, and change the M. In this way we will have a VM which can be used inside Blend. Also our VM will remain same for Desktop and Silverlight so we can package this VM in an independent library(dll). This library will be a public access point. So public API remains same for Desktop and Silverlight.


Please consider that over a period of time many different MVVM concepts have evolved as best practices. So my assumptions below may contradict your's. Please feel free to site some examples as I am very open to change my assumption/opinion.

Thanks in advance :)

解决方案

1. No. This sounds like you don't fully understand what the model is, and you seem to think the model is just the data entity. It isn't - this is a common misunderstanding based on a belief that MVVM is purely a presentation pattern. It's not, it's an architectural pattern, so the model doesn't just refer to the data entity, it relates to the services that the view/viewmodel rely upon.
2. Yes, the view is coupled to the view model.
3. See my answer to point 1. I would expect services, etc, to be injected into the constructor, or injected via property injection.
4. Why? If the VM doesn't need anything that you can't get in both environments, why should they be different.
5. No.
6. No. That really shouldn't be what you are aiming for.


这篇关于关于双目标环境中MVVM的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆