MVC中的M与MVVM中的M是否不同? [英] Is the M in MVC different than in MVVM?

查看:86
本文介绍了MVC中的M与MVVM中的M是否不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对于在这个主题上出现的众多问题,我深表歉意.我了解MVVM和MVC之间的基本区别.我不了解M的确切定义.

First, I'd like to apologize for adding to the myriad of questions on this topic. I understand the basic difference between MVVM and MVC. What I don't understand is the exact definition for the M.

根据我对MVC的理解(与Wikipedia上的内容一致),该模型封装了应用程序的状态(可能还有业务逻辑).它可以让View知道何时发生了更改.可以使用允许存储或检索数据的方法将其实现为一个类.它可能具有允许View侦听数据更改的接口.

In my understanding of MVC (which is consistent with what's out on wikipedia), the Model encapsulates the state (and possibly business logic) of the application. It lets the View know when something's changed. It might be implemented as a class with methods that allow data to be stored or retrieved. It might have an interface that allows the View to listen to changes in data.

我已经阅读了MVVM中关于模型的类似描述.但是,经常会发现有人将模型称为类,这些类代表您在业务领域中正在建模的事物.在他的文章中,约翰·帕帕(John Papa)将模型称为表示描述特定实体的数据点的类.例如,具有诸如CompanyName和CustomerId之类的属性的Customer类.他继续解释说,我有一个班级负责打一个Web服务,以获取我的数据并为我的ViewModel填充我的模型".

I've read similar descriptions of the Model in MVVM. However, frequently, I find people referring to the Model as the classes that represent the things you're modeling in your business domain. In his article, John Papa refers to the Model as, "A class that represents data points describing a specific entity. For example, a Customer class with properties such as CompanyName and CustomerId". He goes on to explain that, "I have a class that is in charge of hitting a web service to go and get my data and fill my Model for my ViewModel".

通常,我将对某些领域概念进行建模的类称为领域类.我同意模型引用这些类,但它不拥有它们.我同意John的观点,即用从服务获得的数据来填充这些类的工作是一个好主意.他似乎暗示这是ViewModel或其他产品的工作.我认为这是模型的关键工作.当然,有一个类(或其他任何东西)可以做到这一点,但是该类是模型本身的一部分.

Normally, I'd call the class that models some domain concept a domain class. I'd agree that the Model references those classes, but it doesn't own them. I'd agree with John that encapsulating the job of filling these classes with data obtained from a service is a good idea. He seems to imply that this is the job of the ViewModel, or some other piece. I thought that this was a key job of the Model. Sure, have a class (or whatever) to do it, but that class is part of the model itself.

MVC/MVVM中的M是模拟某些领域概念的类吗?还是封装应用程序数据的东西?

Is the M in MVC/MVVM the class that model's some domain concept? Or is it the thing that encapsulates the application's data?

我希望有人告诉我我并不疯狂,并且在某种程度上,MS阵营中的人们已经从根本上改变了Model在这些模式中的含义.嗯,虽然我可能是在错误的地方:)

I'd love for someone to tell me I'm not crazy and that somewhere along the line, people in the MS camp have fundamentally changed the idea of what Model means in these patterns. Er, maybe I'm in the wrong place for that though:)

推荐答案

它们是相同的; M指的是域类,也指封装业务逻辑的服务层(如果有的话).

They are the same; the M refers to the domain classes, and also the service layer (if you have one) encapsulating the business logic.

一般原则是这样的:您想要一个胖模型,一个尽可能薄的视图,以及一个控制器或视图模型,它也很薄,但又足够胖以使视图尽可能薄.

The general principle is this: you want a fat model, a view that is as thin as possible, and a controller or viewmodel that is also thin, but fat enough to make the view as thin as possible.

这篇关于MVC中的M与MVVM中的M是否不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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