Model View Presenter
From Wikipedia, the free encyclopedia
Model View Presenter is a software pattern considered as a derivative of the Model-view-controller.
Contents |
[edit] Pattern description
The View is defined as an interface that the Presenter will use for getting and setting data to and from the Model. The View implementation will instantiate the Presenter object and provide a reference to itself (the formal constructor parameter is the View interface while the actual parameter is a concrete View class). When the event methods of the View are triggered, they will do nothing else than invoking a method of the Presenter which have no parameters and no return value. The Presenter will then get data from the View, through the View interface variable that the Presenter stored when the constructor was called. Then the Presenter invokes methods of the Model, and then it sets data from the Model into the View through the View interface.
[edit] Pattern history
It is often claimed that this pattern has "Retired" (11 Jul 06) since Martin Fowler said so[1]. He split the pattern into Supervising Controller [2] and Passive View [3]. Nevertheless, the pattern name still lives on the internet, and a Google search for the pattern still generates 34000+ hits, including a link to an article that has been published in MSDN Magazine [4].
[edit] Pattern implementation in .NET
In a .NET environment the same 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 in .NET can be implemented by both Windows Forms class and an ASPX page (the code-behind class can implement the View interface).
Instead of manually implementing the pattern, one of the Model-View-Presenter frameworks may be used. Below are listed some of such frameworks under the .NET platform.
[edit] Model-View-Presenter frameworks under .NET
[edit] Pattern implementation in Java
In a Java Swing application, the MVP pattern can be used in the same way as with .NET, by letting the Swing class (JFrame) implement a view interface, but it is unclear[5] how you would be able to use the pattern in a web application such as JavaServer Faces, i.e. what class would implement the view interface and be able to set the data in the web page ?
[edit] See also
[edit] References
- ^ Retirement note for Model View Presenter Pattern
- ^ Supervising Controller
- ^ Passive View
- ^ MSDN Magazine article about MVP (August 2006)
- ^ JavaServer Faces - Model-View-Presenter example with JSF implementing the view ?