MVC、MVP 和 MVVM 之间有什么区别? [英] What are the differences between MVC, MVP and MVVM?

查看:31
本文介绍了MVC、MVP 和 MVVM 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,前两个似乎没有什么不同.不管是叫controller还是presenter,看起来还是一样的中介功能.

From what I can gather, the first two don't seem that different. Whether it's called a controller or presenter, it still seems to have the same mediation functions.

MVVM 似乎有点不同,因为控制器似乎更像是框架的一部分,例如 XAML 绑定.

MVVM seems a little different in that the controller seems to be more of a part of the framework, such as with XAML bindings.

《悬崖笔记》对差异的解释是什么?

What is the "Cliff's Notes" explanation of the differences?

推荐答案

不同之处在于来自模型层的数据如何在视图实例中结束.

The difference is in way how data from model layer ends up in the view instances.

  • 经典MVC(以及Model2 MVC)中,视图是主动结构.它从模型层请求信息.Controller 只改变模型层和视图的状态.
  • MVP 中,视图是被动的.相反,presenter 从模型层请求信息并将其传递给视图.您可以在此处详细了解 MVP 模式.
  • MVVM中类似于MVP,但viewmodel必须在将信息传递给视图之前对其进行操作.
  • in classical MVC (and also in Model2 MVC) view is active structure. It requests information from model layer. Controller only changes the state of model layer and view.
  • in MVP the view is passive. Instead presenter request information from model layer and passes it the view. You can read more extensively on about MVP pattern here.
  • in MVVM is similar to MVP, but the viewmodel has to manipulate the information before passing it to view.

MVP 和 MVVM 的区别在于开发过程.在为已知模型层创建表示层时,您将使用 MVP 模式.

The difference between MVP and MVVM is in the development process. You would use MVP pattern, when creating presentation layer for a known model layer.

但是,如果您有预先存在的(或出于某种原因 - 不可更改的)用户界面和预先存在的(或不可更改的)模型层,则必须使用 MVVM.你必须让他们一起工作.这就是视图模型发挥作用的地方.

But you will have to use MVVM, if you have a preexisting (or for some reason - un changeable) user interface and preexisting (or unchangeable) model layer. And you have to make them work together. That's where viewmodel comes into play.

这篇关于MVC、MVP 和 MVVM 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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