繁体   English   中英

理解模型视图演示(MVP)

[英]Understanding Model View Presentation (MVP)

我已经搜索了很多MVP,但我没有找到任何有助于我理解它的好文章。 有没有人知道关于这个主题的任何好文章,用现实世界的例子来帮助我更好地理解它?

提前致谢。

查看我对帖子的回答,这可能对您有所帮助:

ASP.net Model View Presenter值得花时间吗?

它经历了MVP和MVC之间的差异,因为两者经常形成对比。
此外,还有一些有用的链接,展示了如何轻松地将MVP模型适用于现有的ASP.Net网站。

HTH

这是一个专门在asp.net上做mvp的网站: http ://webformsmvp.com/ MVP作为一种模式有点过时 - MVC(它有一个很棒的asp.net框架和支持)和MVVM(事实上的WPF模式)已经基本上接管了。 实际上,Martin Fowler(MVP的发明者)已经证明,该模式确实应该分为两种模式:Passive View和监督控制器在他的网站上: http//martinfowler.com/eaaDev/ModelViewPresenter.html

如果您想更深入地了解这种模式,请查看Web客户端软件工厂2010工具。

此工具主要用于创建复合Web应用程序(模块),但视图是使用MVP模式实现的。 如果您要维护传统的ASP.Net代码,或者如果您想在ASP.Net范例中进一步挖掘,那么检查此工具的源代码是一个很好的起点。

此工具要求您安装Visual Studio的几个扩展,然后,您可以创建一个特殊的Web项目,为您实现MVP,它将向Visual Studio添加上下文菜单以方便任务

例:

  • 创建一个新项目

创建一个项目

  • 使用演示者添加视图

使用演示者添加视图

  • 检查生成的文件

检查生成的文件

  • 检查默认生成的代码:

      public partial class MyNewView : Microsoft.Practices.CompositeWeb.Web.UI.Page, IMyNewViewView { private MyNewViewPresenter _presenter; protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this._presenter.OnViewInitialized(); } this._presenter.OnViewLoaded(); } [CreateNew] public MyNewViewPresenter Presenter { get { return this._presenter; } set { if (value == null) throw new ArgumentNullException("value"); this._presenter = value; this._presenter.View = this; } } // TODO: Forward events to the presenter and show state to the user. // For examples of this, see the View-Presenter (with Application Controller) QuickStart: // } public interface IMyNewViewView { } public class MyNewViewPresenter : Presenter<IMyNewViewView> { // NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller // The code will not work in the Shell module, as a module controller is not created by default // // private IShellController _controller; // public MyNewViewPresenter([CreateNew] IShellController controller) // { // _controller = controller; // } public override void OnViewLoaded() { // TODO: Implement code that will be executed every time the view loads } public override void OnViewInitialized() { // TODO: Implement code that will be executed the first time the view loads } // TODO: Handle other view events and set state in the view } 

抓住工具的战利品:

顺便说一句,如果你要开始一个新项目,使用MVC应该是一个更好的主意,如果你需要编写一个现有的应用程序,你可以在Web客户端软件工厂中作为MVP实现的基础。

如果您感兴趣,我认为有一个改进现有应用程序以使用Web客户端软件工厂的工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM