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

推荐订阅源

酷 壳 – 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

博客园 - thh

svm资料收集 向量空间及其他相关数学结构 - thh 难题--autoconf、automake、libtool Linq 中不爽之处 关于UI设计的文章汇总 Window Live Writer LR 剖析器 Guid、Int、BigInt编号的速度和存储空间的比较 - thh 静态构造函数线程安全的几个版本[转载] 区域性 ID 2155 (0x086B)不是受支持的区域性 解决方法 - thh windbg给clr设置断点 python ip和int 互转函数 - thh interface与pojo类之间的关系 关于OpenId Python SOAPpy访问asp.net web service 代码 Python SOAPpy 和 .net WebService - thh Type.GetType 获得本Assembly以外的类型 NHibernate 代码生成工具 - thh NHibernate使用笔记
MVP模式中的P和V关系
thh · 2007-10-09 · via 博客园 - thh

   MVP模式实现了View Interface,让Controller代码从View层很好的分离出来,逻辑也更清晰。这个和传统的Page_Load的面条代码相比,有很明显的进步。采用MVP模式之后,Page_load里的代码明显减少了。对于网站开发而言,你可以在dll里写出控制器代码和视图的接口了,以后页面的具体布局,风格也就可以少抄心很多了。但是新问题也产生了:
    1、Presenter 中往往有好多种状态,比如简单的登陆界面,至少有3个状态:登陆前,登陆错误,登陆成功。是应该把这3个状态做成一个View Interface,还是做成3个独立的View Interface呢?按照OO的原则,类应该保持单一的职责,所以选中3个独立的View Interface。但是这个在Asp.net中实现起来好像并不容易。如果设计成一个,那么在View 中,必然存在很多的if,这里简单的称为 界面逻辑。如果状态多了,这些界面逻辑也可能成为一堆面条。所以这里是一个问题。我也看过类似 Response.Redirect的方案,这个增加了Http请求的数目。
      可能的解决办法,是让Presenter支持多个View,增加自动加载视图的功能,类似CakePhp。

   2、事件中调用Presenter的代码问题。如果有一个比较复杂的页面,可能有多个Presenter类,并且页面会响应很多事件。但是如果要仔细的区分这些事件,在Asp.net如果不采用WebControl,做起来就比较的麻烦。因为HtmlControl和Html代码之类的都支持 回发事件,并且在Asp.net中操作不方便。

   以上是我想到的2个问题,也是在实际使用中感觉需要改进的问题。总体来说,MVP模式是基于Asp.net的事件模型的重大改进啊,如果你现在还为Page_Load,OnClick中的重复代码、复杂逻辑感到发愁,建议了解一下MVP模式。

参考:

http://www.codeproject.com/useritems/Advanced_MVP.asp