Model–view–presenter

Model–view–presenter

Model–view–presenter (MVP) is a derivative of the model–view–controller (MVC) software pattern, also used mostly for building user interfaces.

In MVP the presenter assumes the functionality of the "middle-man" (played by the controller in MVC). Additionally, the view is responsible for handling the UI events (like mouseDown, keyDown, etc), which used to be the controller's job. Eventually, the model becomes strictly a domain model.

Contents

Pattern description

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 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()   // Constructor
    {
        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.

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 with common layers but it can also be seen as a presenter layer of its own between the application layer and the user interface layer.

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.[1] After Taligent's demise in 1997, Andy Bower and Blair McGlashan of Dolphin Smalltalk adapted the MVP pattern to form the basis for their Smalltalk user interface framework.[2] In 2006, Microsoft began incorporating MVP into their documentation and examples for user interface programming in the .NET framework.[3] 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 an article by Martin Fowler[4] and another by Derek Greer[5]

Implementation in .NET

The .NET 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 Web application, a Windows Forms application, or a Silverlight 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. Below is a list of such frameworks under the .NET platform.

Frameworks

Implementation in Java

In a Java (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 requires only that some component implement the view interface. The same approach is possible using the Echo2 web framework.

MVP can be implemented in Java SE (Swing and AWT) applications using the Biscotti framework.

Frameworks

See also

References

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Model View Presenter — is a software pattern considered as a derivative of the Model view controller. 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… …   Wikipedia

  • Model View Presenter — (Abkürzung: MVP; wörtlich etwa ‚Modell Ansicht Präsentator‘) ist ein Entwurfsmuster in der Softwareentwicklung, das aus dem Model View Controller (Abkürzung: MVC) hervorgegangen ist. Es beschreibt einen neuartigen Ansatz, um das Modell (engl.… …   Deutsch Wikipedia

  • Model-View-Presenter — Шаблон проектирования Model View Presenter Model View Presenter (MVP)  шаблон проектирования, производный от MVC, который используется в основном для построения пользовательского интерфейса. В MVP Presenter берет на себя функциональность… …   Википедия

  • Model-view-presenter — Le Modèle Vue Presentation (en abrégé MVP, de l anglais Model View Presenter) est un Patron de conception, considéré comme un dérivé du Patron de conception Modèle Vue Contrôleur. Catégorie : Patron de conception …   Wikipédia en Français

  • Model-view-controller — (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the …   Wikipedia

  • Model View Controller — Konzept. Hinweis: die durchgezogene Linie symbolisiert eine direkte Assoziation, die gestrichelte eine indirekte Assoziation (zum Beispiel über einen Beobachter). Model View Controller (englisch  model view controller (MVC), deutsch auch: M …   Deutsch Wikipedia

  • Model–view–controller — A general representation of the MVC design pattern. Model view controller concept. The solid line represents a direct as …   Wikipedia

  • Model View ViewModel — The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of the Presentation Model design pattern introduced by Martin Fowler.[1] Largely based on the Model view… …   Wikipedia

  • Model-View-Controller — Шаблон проектирования Model View Controller Кон …   Википедия

  • Model-View-ViewModel — Шаблон проектирования Model View ViewModel Шаблон Model View ViewModel  применяется при проектировании архитектуры приложения. Первоначально был представлен сообществу Джоном Госсманом (John Gossman) в 2005 году как модификация шаблона… …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”