Model-view-presenter (MVP) is a user interface design pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic.
- The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
- The view is an interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
- The presenter acts upon the model and the view. It retrieves data from repositories (the model), persists it, and formats it for display in the view.
Normally, the view as implementation instantiates the concrete presenter object, providing a reference to itself. The following C# code demonstrates a simple view constructor, where ConcreteDomainPresenter implements the IDomainPresenter interface:
public class DomainView: IDomainView { private IDomainPresenter _domainPresenter; public DomainView() { this._domainPresenter = new ConcreteDomainPresenter(this); } }
The degree of logic permitted in the view varies among different implementations.
At one extreme, the view is entirely passive, forwarding all interaction operations to the presenter. In this formulation, when a user triggers an event method of the view, it does nothing but invoke a method of the presenter which has no parameters and no return value. The presenter then retrieves data from the view through methods defined by the view interface. Finally, the presenter then operates on the model and updates the view with the results of the operation.
History
The model-view-presenter software pattern originated in the early 1990s at Taligent, a joint venture of Apple, IBM, and HP, and was the underlying programming model for application development in Taligent’s C++-based CommonPoint environment.
The pattern was later migrated by Taligent to Java and popularized in a paper by Taligent CTO Mike Potel. After the demise of Taligent in 1997, the MVP pattern was adapted by Andy Bower and Blair McGlashan of Dolphin Smalltalk to form the basis for their Smalltalk user interface framework.
In 2006, Microsoft began incorporating MVP into their documentation and examples for user interface programming in the .NET framework. The evolution and multiple variants of the MVP pattern, including the relationship of MVP to other design patterns such as MVC, were analyzed in detail in articles by Martin Fowler and Derek Greer.
In a .NET environment the same model and presenter class can be used for ASP.NET application and a Windows Forms application. The presenter gets and sets information from/to the view through an interface that can be implemented by both a Windows Forms class and an ASPX page.
Instead of manually implementing the pattern, one of the model-view-presenter frameworks may be used. Below is a list of such frameworks under the .NET platform.
Model-view-presenter frameworks under .NET
- MVC# Framework
- NMVP Framework
- Web Client Software Factory
- Evolution.Net MVP Framework
- ASP.NET Web Forms Model-View-Presenter (MVP)
- Scott Cate’s WebLog – Very Quick MVP Pattern to Use with ASP.NET
- ASP.NET Wiki – MVP (Model View Presenter) Framework
Information Courtesy to WikiPedia.org, ASP.NET Wiki, Weblogs of Scott Cate, CodeProject.com, EggHeadCafe.com
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.