Model–view–presenter
   HOME

TheInfoList



OR:

Model–view–presenter (MVP) is a derivation of the
model–view–controller Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divides the related program logic into three interconnected elements. These elements are: * the model, the internal representat ...
(MVC)
architectural pattern Software architecture pattern is a reusable, proven solution to a specific, recurring problem focused on architectural design challenges, which can be applied within various architectural styles. Examples Some examples of architectural patte ...
, and is used mostly for building user interfaces. In MVP, the ''presenter'' assumes the functionality of the "middle-man". In MVP, all presentation logic is pushed to the presenter.


History

The model–view–presenter software pattern originated in the early 1990s at
Taligent Taligent Inc. (a portmanteau of "talent" and "intelligent") was an American software company. Based on the Pink object-oriented operating system conceived by Apple in 1988, Taligent Inc. was incorporated as an Apple/IBM partnership in 1992, and ...
, a joint venture of
Apple An apple is a round, edible fruit produced by an apple tree (''Malus'' spp.). Fruit trees of the orchard or domestic apple (''Malus domestica''), the most widely grown in the genus, are agriculture, cultivated worldwide. The tree originated ...
,
IBM International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American Multinational corporation, multinational technology company headquartered in Armonk, New York, and present in over 175 countries. It is ...
, and
Hewlett-Packard The Hewlett-Packard Company, commonly shortened to Hewlett-Packard ( ) or HP, was an American multinational information technology company. It was founded by Bill Hewlett and David Packard in 1939 in a one-car garage in Palo Alto, California ...
. MVP is the underlying programming model for application development in Taligent's C++-based CommonPoint environment. The pattern was later migrated by Taligent to
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
and popularized in a paper by Taligent CTO Mike Potel. After Taligent's discontinuation in 1998, Andy Bower and Blair McGlashan of
Dolphin Smalltalk Dolphin Smalltalk, or "Dolphin" for short, is an implementation of the programming language Smalltalk for Microsoft Windows. The Dolphin 7 version release coincided with the project becoming free and open-source software under an MIT License. ...
adapted the MVP pattern to form the basis for their Smalltalk user interface framework. In 2006,
Microsoft Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
began incorporating MVP into its 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, is discussed in detail in an article by Martin Fowler and another by Derek Greer.


Overview

MVP is a user interface
architectural pattern Software architecture pattern is a reusable, proven solution to a specific, recurring problem focused on architectural design challenges, which can be applied within various architectural styles. Examples Some examples of architectural patte ...
engineered to facilitate
automated Automation describes a wide range of technologies that reduce human intervention in processes, mainly by predetermining decision criteria, subprocess relationships, and related actions, as well as embodying those predeterminations in machine ...
unit testing Unit testing, component or module testing, is a form of software testing by which isolated source code is tested to validate expected behavior. Unit testing describes tests that are run at the unit-level to contrast testing at the Integration ...
and improve the
separation of concerns In computer science, separation of concerns (sometimes abbreviated as SoC) is a design principle for separating a computer program into distinct sections. Each section addresses a separate '' concern'', a set of information that affects the code o ...
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 a passive 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), and formats it for display in the view. Normally, the view implementation instantiates the concrete presenter object, providing a reference to itself. The following C# code demonstrates a simple view constructor: public class Presenter : IPresenter public class View : IView 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 that 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 operates on the model and updates the view with the results of the operation. Other versions of model–view–presenter allow some latitude with respect to which class handles a particular interaction, event, or command. This is often more suitable for web-based architectures, where the view, which executes on a client's browser, may be the best place to handle a particular interaction or command. From a layering point of view, the presenter class might be considered as belonging to the application layer in a multilayered architecture system, but it can also be seen as a presenter layer of its own between the application layer and the
user interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
layer.


Implementations


.NET

The
.NET The .NET platform (pronounced as "''dot net"'') is a free and open-source, managed code, managed computer software framework for Microsoft Windows, Windows, Linux, and macOS operating systems. The project is mainly developed by Microsoft emplo ...
environment supports the MVP pattern much like any other development environment. The same model and presenter class can be used to support multiple interfaces, such as an
ASP.NET ASP.NET is a server-side web-application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, applications and services. The name stands for Ac ...
Web application or a
Windows Forms Windows Forms, also known as WinForms, is a free, open-source graphical user interface (GUI) class library for building Windows desktop applications, included as a part of Microsoft .NET, .NET Framework or Mono, providing a platform to write c ...
application. The presenter gets and sets information from/to the view through an interface that can be accessed by the interface (view) component. In addition to manually implementing the pattern, a model–view–presenter framework may be used to support the MVP pattern in a more automated fashion.


Java

In a
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
( AWT/ Swing/ SWT) application, the MVP pattern can be used by letting the user interface class implement a view interface. The same approach can be used for Java web-based applications, since modern Java component-based Web frameworks allow development of client-side logic using the same component approach as thick clients. Implementing MVP in
Google Web Toolkit Google Web Toolkit (GWT ), or GWT Web Toolkit, is an open-source software, open-source set of Programming tool, tools that allows web developers to create and maintain JavaScript Front and back ends, front-end applications in Java (programming ...
requires only that some component implement the view interface. The same approach is possible using
Vaadin Vaadin () is an open-source web application development platform for Java. Vaadin includes a set of Web Components, a Java web framework, and a set of tools that enable developers to implement modern web graphical user interfaces (GUI) using the ...
or the Echo2 Web framework. Java frameworks include the following: * JavaFX * Echo2 *
Google Web Toolkit Google Web Toolkit (GWT ), or GWT Web Toolkit, is an open-source software, open-source set of Programming tool, tools that allows web developers to create and maintain JavaScript Front and back ends, front-end applications in Java (programming ...
* JFace * Swing *
Vaadin Vaadin () is an open-source web application development platform for Java. Vaadin includes a set of Web Components, a Java web framework, and a set of tools that enable developers to implement modern web graphical user interfaces (GUI) using the ...
* ZK


PHP

As of
PHP PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. ...
's flexible runtime environment, there are wide possibilities of approaches of an application logic. Implementation of model layer is left on the end application programmer. PHP frameworks include the following: * CodeIgniter *
Laravel Laravel is a open-source software, free and open-source PHP-based web framework for building web applications. It was created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) ar ...
* Nette Framework


See also

*
Multitier architecture In software engineering, multitier architecture (often referred to as ''n''-tier architecture) is a client–server architecture in which presentation, application processing and data management functions are physically separated. The most wide ...
*
Model–view–controller Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divides the related program logic into three interconnected elements. These elements are: * the model, the internal representat ...
* Model–view–viewmodel *
Presenter first (software approach) Presenter first is a software development approach that combines the ideas of the model–view–presenter (MVP) design pattern, test-driven development, and feature-driven development. Approach Presenter first concentrates on transforming each ...


References


External links


Model View Presenter Example from the GWT project.

Model-View-Presenter implementation thoughts at StackExchange
{{DEFAULTSORT:Model-view-presenter Software design patterns Architectural pattern (computer science)