简体   繁体   中英

Understanding Model View Presentation (MVP)

I have searched a lot for MVP, but I haven't found any good articles that help me understand it very well. Does anyone know of any good articles on the subject, with real-world examples to help me understand it better?

Thanks in advance.

Check out my answer to a so post, which may help you:

Is ASP.net Model View Presenter worth the time?

It goes through the differences between MVP and MVC, as often the two are contrasted.
Also, there's some helpful links, which show how to easily fit an MVP model to an existing ASP.Net website.

HTH

Here's a site devoted to doing mvp on asp.net: http://webformsmvp.com/ MVP as a pattern is kinda obsolete - MVC (which has a great asp.net framework and support) and MVVM (the de facto pattern of WPF) have largely taken over. In fact, Martin Fowler (MVP's inventor) has documented that the pattern really ought to be split into two patterns, Passive View and Supervising Controller on his site: http://martinfowler.com/eaaDev/ModelViewPresenter.html

If you would like to dig more into this patter, take a look at the Web Client Software Factory 2010 tool.

This tool is basically used to create composite web applications (modules) but the views are implemented using the MVP pattern. If you are going to maintain traditional ASP.Net code or if you want to dig a little bit more in the ASP.Net paradigm, checking the source code of this tool is a great place to start.

This tool requires you to install a couple of extensions to Visual Studio, and after that, you can create a special web project that will implement the MVP for you, it will add contextual menus to Visual Studio to facilitate the tasks

Example:

  • Create a new project

创建一个项目

  • Add a view with a presenter

使用演示者添加视图

  • Check the generated files

检查生成的文件

  • Check the default generated code:

      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 } 

Take a loot at the tool:

BTW, If you are going to start a new project, it should be a better idea to use the MVC, if you need to redactor an existing application, you can take as a base the implementation of the MVP in the Web Client Software Factory.

If you are interested, I think there's a work-through in order to convert an existing application to use the Web Client Software Factory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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