Presenter、Presentation Model、ViewModel 和 Controller 之间有什么区别? [英] What are the differences between Presenter, Presentation Model, ViewModel and Controller?

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

问题描述

我非常清楚这些模式中的每一个是如何工作的,并且知道它们之间的一些细微差别,但它们彼此之间真的有很大不同吗?

I have a pretty good idea how each of these patterns work and know about some of the minor differences between them, but are they really all that different from each other?

在我看来,Presenter、Presentation Model、ViewModel 和 Controller 本质上是相同的概念.

It seems to me that the Presenter, Presentation Model, ViewModel and Controller are essentially the same concept.

为什么我不能将所有这些概念归类为控制器?我觉得这可能会大大简化整个想法.

Why couldn't I classify all of these concepts as controllers? I feel like it might simplify the entire idea a great deal.

谁能清楚地描述一下它们的区别?

Can anyone give a clear description of their differences?

我想澄清一下,我确实了解这些模式的工作原理,并且已经在一种或另一种技术中实现了其中的大部分.我真正要寻找的是某人对这些模式之一的体验,以及为什么他们不会将他们的 ViewModel 视为控制器.

I want to clarify that I do understand how the patterns work, and have implemented most of them in one technology or another. What I am really looking for is someone's experience with one of these patterns, and why they would not consider their ViewModel a Controller for instance.

我会为此提供一些声誉点,但我正在寻找一个非常好的答案.

I'll give some reputation points for this, but I'm looking for a really good answer.

推荐答案

除了已经提到的优秀读物 (Fowler & Miller) 并回复您关于控制器/演示者/...之间差异的观点开发者的观点:

Besides the already mentioned great reads (Fowler & Miller) and to reply to your point on differences among controller/ presenter/ ... from the developer's point of view:

MVC 中的控制器:

  • Controller 是作为用户交互的结果而被调用的实际组件.(开发人员不必编写代码将调用委托给控制器.)

  • Controller is the actual component that gets called as a result of user interaction. (Developer does not have to write code to delegate calls to the Controller.)

Controller 以某种方式从 View/context/bag/获取当前值,但您不会真正说它与 View 交互.

Controller gets current values somehow from the View/ context/ bag/ whatever, but you would not really say that it interacts with the View.

MVP 演示者:

  • Presenter 具有由视图调用的方法,视图是用户交互时实际接收控件的组件.(开发人员必须在 View 中编写一些代码才能调用 Presenter.)

  • Presenter has methods called by the View, which is the actual component receiving control upon user interaction. (Developer has to write some code in the View in order to call the Presenter.)

Presenter 以某种方式从 View 获取当前值,或者在调用时从 View 接收它们.Presenter 调用 View 上的方法以设置其状态(Josh Smith 说填充它).由 Presenter 调用的 View 方法可能在其主体中执行了几个小设置.

Presenter gets current values somehow from the View or receive them from the View upon call. Presenter calls methods on the View in order to set its state (populate it says Josh Smith). A View method called by the Presenter might have several small settings performed in its body.

Presenter 没有明确显示应用程序工作流的概念.它通常被认为是将控制权返回给调用视图.

Presenter does not explicitly show a notion of application workflow. It is usually thought of as returning control to the calling View.

PM 中的演示模型:

  • PresentationModel 有被 View 调用的方法,View 是实际的组件在用户交互时接收控制.(开发人员必须在 View 中编写一些代码才能调用 PresentationModel.)

  • PresentationModel has methods called by the View, which is the actual component receiving control upon user interaction. (Developer has to write some code in the View in order to call the PresentationModel.)

PresentationModel 与 Presenter 相比,与 View 的交流更加健谈.它还包含更多逻辑,以便找出要在视图中应用的所有设置的值,并在视图中实际设置这些设置.(反过来那些View方法几乎没有逻辑.)

PresentationModel has a much more chatty communication with View compared to a Presenter. It also contains more logic in order to figure out the value of all the settings to apply in the View, and to actually set those in the View. (Those View methods in turns have almost no logic.)

PresentationModel 没有明确显示应用程序工作流的概念.它通常被认为是将控制权返回给调用视图.

PresentationModel does not explicitly show a notion of application workflow. It is usually thought of as returning control to the calling View.

MVVM 中的 ViewModel:

  • ViewModel 具有由 View 调用的方法(和设置的属性),View 是在用户交互时接收控制的实际组件.(开发人员必须在 View 中编写一些(声明性)代码才能调用 ViewModel.)

  • ViewModel has methods called (& properties set) by the View, which is the actual component receiving control upon user interaction. (Developer has to write some (declarative) code in the View in order to call the ViewModel.)

与 PresentationModel 相比,ViewModel 没有明确地与 View 进行交流(即它不会经常调用 View,框架会这样做).但是它有很多属性可以通过视图设置将 1 映射到 1.它仍然包含相同的逻辑来计算所有这些设置的值.

ViewModel has not an explicitly chatty communication with View compared to PresentationModel (i.e. it does not call View a lot, the framework does it). But it has a lot of properties that map 1 to 1 with View settings. It still contains the same logic to figure out the value of all those settings.

ViewModel 没有明确显示应用程序工作流的概念.它通常被认为是将控制权返回给调用视图.

ViewModel does not explicitly show a notion of application workflow. It is usually thought of as returning control to the calling View.

以某种方式复制 Josh Smith 所说的内容 (http://msdn.microsoft.com/en-us/magazine/dd419663.aspx):MVVM 模式是 PM 的一个特例,它利用框架(如 WPF/SL)来编写更少的代码.

Copying somehow what Josh Smith says (http://msdn.microsoft.com/en-us/magazine/dd419663.aspx): MVVM pattern is a special case of PM that takes advantage of a framework (like WPF/SL) in order to write less code.

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

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