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

本文是小编为大家收集整理的关于MVC、MVP和MVVM之间有什么区别?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

根据我可以收集的东西,前两个似乎没有那么不同.无论是称为控制器还是演示者,它似乎仍然具有相同的中介功能.

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

差异的"悬崖笔记"解释是什么?

推荐答案

区别在于模型层的数据如何在视图实例中结束.

  • 在经典MVC (以及Model2 MVC中)视图是活动结构.它从模型层请求信息. 控制器仅更改模型层的状态和视图.
  • 在 MVP中视图是被动的.而是主持人从模型层请求信息,并将其传递给视图.您可以更广泛地了解有关MVP模式在这里.
  • mvvm 与MVP相似,但是 viewModel 必须在传递信息之前操纵信息.

MVP和MVVM之间的差异在开发过程中.为已知模型层创建演示层时,您将使用MVP模式.

但是,如果您具有先前存在(或出于某种原因 - 不可变的)用户界面和先前存在(或不变的)型号层,则必须使用MVVM.而且您必须使他们一起工作.那是ViewModel发挥作用的地方.

本文地址:https://www.itbaoku.cn/post/627688.html

问题描述

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 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.

  • 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.

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.

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.