模型-视图-视图模型 (MVVM) 模式的优势是否值得开销? [英] Are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

查看:27
本文介绍了模型-视图-视图模型 (MVVM) 模式的优势是否值得开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主题中提出的问题是:模型-视图-视图模型 (MVVM) 模式的优势值得开销吗?

The question is stated in the subject: are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

在许多情况下,实现视图模型涉及复制模型属性以及有时在模型和视图模型数据成员之间同步的相当大的开销.例如,目前在 Silverlight 4 &WCF RIA,不生成视图模型(如果开发人员遵循 MVVM 模式,则由他创建视图模型,通常在 ViewModel 中复制相应模型的属性,这些属性没有任何意义,只是将模型称为存储).

In many cases, implementing the view model involves quite significant overhead of duplicating the Model properties and sometimes synchronization between Model and ViewModel data members. For example, currently in Silverlight 4 & WCF RIA, View Models are not generated (if the developer follows the MVVM pattern, it is up to him to create the view models, often duplicating the corresponding Model's properties at ViewModel, that do nothing significant but refer to Model as the storage).

为什么不扩展 Model 类,提供额外的属性使其易于被 View 使用?

Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

推荐答案

为什么不扩展 Model 类,提供额外的属性使其易于被 View 使用?

Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

在简单的情况下,这就是 ViewModel 所做的一切 - 包装模型,以便它以可由 View 使用的方式进行扩展.如果您的模型可以直接绑定,欢迎您这样做.

In the simple cases, this is all the ViewModel is doing - wrapping up the Model so that its extended in a way that's consumable by the View. If your Model can be bound directly, you're welcome to do so.

话虽如此,ViewModel 层不仅仅是包装模型 - 这也是应用程序特定逻辑 - 即:应用程序的管道将发生的地方.必须正确地从模型类发出请求并将逻辑组合在一起.

That being said, there is more to the ViewModel layer than just wrapping the model - this is also where the application specific logic - ie: the application's plumbing, will occur. Something has to make the requests from the Model classes correctly and compose together the logic.

这篇关于模型-视图-视图模型 (MVVM) 模式的优势是否值得开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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