惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 风满袖

如何进行有效的沟通(二) 如何进行有效的沟通(一) SOA——概念 (转)Locale 详解 A XMLBean Tip 在Weblogic8.1.4服务器上安装Alphablox8.4 BI相关的术语 开源BI系统简述 如何收集项目需求 Prefactoring——Guidelines Prefactoring——Introduction Create C++ Object Dynamically Success/Failure Criteria for Software Projects AJAX Secutiry and AJAX Applications Accessible -- Many Tutorials and Articles A NHibernate Helper Kit Apache——Config WebDAV 3D Desktop Some Funny Development Methodologies -- XXX Driven Development Why I hate Web 2.0/AJAX? Here are some reasons...
MVP——Model-Viewer-Presenter
风满袖 · 2006-07-12 · via 博客园 - 风满袖

MVP——Model-Viewer-Presenter

Introduction

这里的MVP不是微软的那个MVP,而是一个设计模式Model-Viewer-Presenter。最早(2000年)由IBM开发出来的一个针对C++Java的编程模型,它是MVC模式的变种。其目的就在于提供a cleaner implementation of the Observer connection between Application Model and view

MVP

在企业应用中,对用户有用的是各种数据,他们通过UI以各种不同的方式管理这些数据。对于开发者而言,需要给用户提供各种UI,通过响应用户操作UI时触发的各种Event来执行一定的业务逻辑,从而操控数据,数据变化后还需要更新显示,给用户予以提示。UI是容易变化的,且是多样的,一样的数据会有N种显示方式;业务逻辑也是比较容易变化的。为了使得Application具有较大的弹性,我们期望将UI、逻辑(UI的逻辑和业务逻辑)和数据隔离开来,而MVP是一个很好的选择。

Model

MVC中的Model是一样的含义——The Domain Data,包括SelectionCommand

图:

Viewer

呈现Model,且处理UI的事件(Handle UI Event)。

Presenter

代替了Controller,它比Controller担当更多的任务,也更加复杂。Presenter处理事件,执行相应的逻辑,这些逻辑映射到ModelCommand以操作Model。那些处理UI如何工作的代码基本上都位于PresenterPresenter如同一个乐队的指挥家,表现和协调整个Application,它负责创建和协调其它对象。

ModelView使用Observer模式进行沟通;而PresenterView则使用Mediator模式进行通信;Presenter操作Model则使用Command模式来进行。从上面我给的链接MVP中可以找到讲解MVPPDF文件,该文档中详细说明了MVP的设计思想。

如果想知道MVCMVP有什么不同,那可以看这里

Example

光看理论还不能掌握一个架构模式,得看看实际的例子才行,我在codeproject上发现一篇不错的文章《Model View Presenter with ASP.NET》,作者指出了ASP.NETcode-behind编程模型的各种缺点,然后讲解了如何将MVP应用到ASP.NET Application中,而无须使用复杂的Framework

更多的例子:

http://www.mattberther.com/2005/01/000589.html

http://codebetter.com/blogs/jeremy.miller/articles/129546.aspx

http://weblogs.asp.net/pgreborio/archive/2005/01/07/348021.aspx

http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/default.aspx

如果不介意看smalltalk的话(其实关键是思想):

http://www.object-arts.com/docs/index.html?modelviewpresenter.htm

http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Overviews/ModelViewPresenter.htm

另外还有一个Jean-Paul TV
http://weblogs.asp.net/bsimser/archive/2006/07/18/Model_2D00_View_2D00_Presenter-Pattern-with-SharePoint-Web-Parts.aspx

Postscript

MVC模式几乎是人人都知道的,但MVP似乎知名度小得多,很少有人提及。其实Martin Fowler讲解过该模式。虽然它创建之初是为了针对C++Java的,但在象C#这样的语言中也一样可以应用它。使用MVP后,我们可以提高对ModelPresenter的复用,比如可以对ModelPresenter不做修改,而能提供ASP.NET Web Form Windows Form。总之,MVP是一个值得去研究的架构模式。