Model-View-Presenter 是一种架构模式,它定义了 UI 级别的行为和逻辑结构。MVP 将表示的逻辑(例如与后端服务和业务层的交互)与显示按钮和界面组件的机制分开。
被动视图是模型-视图-演示者模式的一个子集。
基本模型视图演示者图
从外到内,被动视图的架构如下所示:
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