演示模型与MVP(被动视图)

时间:2016-04-03 03:22:25

标签: design-patterns architecture mvp presentation-model

我正在尝试学习演示模型模式,在我的尝试中,我对演示模型和MVP - 被动视图的区别感到困惑。特别是当Presentation Model执行同步而不是View时。这个问题是previous question对这个问题的延伸。

Martin Fowler提供了演示模型在Article中进行同步的可能性。

  

引用视图的表示模型通常维护表示模型中的同步代码。由此产生的观点非常愚蠢。该视图包含任何动态状态的setter,并引发事件以响应用户操作。视图实现了接口,允许在测试Presentation Model时轻松存根。 Presentation Model将通过更改任何适当的状态并重新加载整个视图来观察视图并响应事件。因此,可以轻松测试同步代码,而无需实际的UI类。

如果演示模型正在同步,我不完全理解它与MVP(被动视图)的区别。他的article about Passive View显示了一个使用同步更新视图的示例。

因此,演示模型引用视图(和同步)的演示模型模式是否与MVP(被动视图)相同?

1 个答案:

答案 0 :(得分:-1)

Model-View-Presenter是一种体系结构模式,它定义了UI级别的行为和逻辑结构。 M-V-P将显示的逻辑(例如与后端服务和业务层交互)与显示按钮和界面组件的机制分开。

Passive View是Model-View-Presenter模式的子集。 Basic Model view presenter diagram

从外部看,Passive View的架构看起来像这样:

UI – The User Interface reflects what is going on beneath it by implementing one or more View interfaces
Presenter – The Presenter receives interactions from the UI or Model and updates the Views it is attached to
Model – The model is a facade or black box in our diagram, behind which is a business logic layer and data layer

在扁平体系结构中,我们将从界面收集数据,可能会进行一些业务和数据验证,然后使用存储过程或内联SQL将其直接保存到数据库中。定义数据访问层(或类似于实体框架的数据模型)允许我们的应用程序在对应用程序有意义且一致地存储和检索的内聚定义对象上运行。定义业务逻辑层允许我们以与业务一致且在应用程序内部一致的方式集中操作应用程序中的实体的业务规则,从而最大限度地降低在更改业务流时发生的风险。分离填充输入和响应按钮上的按钮的逻辑,从传递给最终用户的信息和对其输入的概念响应,允许系统通过任意数量的接口一致地与用户交互到同一应用程序。

我的示例应用程序有几个功能和非功能需求:

Functional – Display product number, name, list price, and available quantity in tabular format
Functional – Provide a basic search input and button to search product names
Non-Functional – Implement an M-V-P pattern – Obviously the purpose of this whole exercise
Non-Functional – Use a simple model stack that can be easily replaced with a Service-Oriented one at a later time
Non-Functional – Build with the idea that we will later create a Silverlight or WPF front-end
Non-Functional – Make pretty pictures for article