SIGN UP MEMBER LOGIN:    
ARTICLE

Model View Presenter Design Pattern

Posted by John Charles Olamendy Articles | Design & Architecture October 22, 2011
In this article I will explain the principles of this design pattern.
Reader Level:

Introduction

Model View Presenter is the new kid on the block in the Enterprise Architecture design patterns which has derived from the classic model-view-presenter.
 
In this article I will explain the principles of this design pattern.

The Model View Presenter pattern

When you design the architecture of an enterprise application, you can realize that there are logical common layers common to all the architecture decisions:

  • User interface layer (UI controls, views and presentation logic)
  • Application Layer (services, workflow orchestration)
  • Domain Layer (business objects and services, domain model entities, business rules)
  • Resource access layer (data access and persistent to database systems, logging, access to network resources, and composition with external services)

    Model View Presenter (MVP) design pattern is an evolution of the traditional Model View Controller (MVC) to improve the separation of concerns and facilitate the automatic unit testing.

The model layer is the composition of the application layer and domain layer. That is, when the view receives an action, then the action triggers a command to the application layer through the presenter layer. The application knows the business logic of the solution and how to communicate to the domain entities and business services in the domain layer.

The view layer is the user interface (using GUI controls and widgets) to gather and display data as well as to route user commands to the presenter layer to act upon the data. The view must be as passive as possible (made of interactive controls waiting for user actions), so it's so simple and logic-free. The only possible logic to include in this layer is data binding techniques and the validation using desktop techniques as well as client-side Web techniques such Jscript and jQuery.

The presenter layer acts upon the model and the view. That is, the only way for the communication between the view layer and model is through the presenter layer (there is no direct contact). This layer can use the classic controller to route the application from one view to another view (manage the navigation logic to all the views you can reach from a particular one) as well as to manage the complexities regarding the input and output data such as loading, transformations, etc. The controller object is centralized to hold the navigation rules and other features such as security and logging; therefore it must be created upon startup and is a global object. You can implement this global object following the Singleton design pattern. It's remarkable to remember that the Presenter is also responsible for the presentation navigation of the solution as well as the enabling or disabling subviews. A subview is essentially a part of the screen such as a panel or child windows. Finally, let's say that all the communication between the model, view and presenter objects is done through well established interfaces. The Figure 1 shows the reference model of the Model View Presenter design pattern. In this model the Presenter is merely a mediator between the View and the Model, and in this way the Presenter logic is inherently more testable. By defining a contract for the View (through the IView interface), you separate the UI elements from others in the solution, so the view can be replace with other view implementing the same contracts as well as we can create mockable views. The same Presenter can be shared between different solutions.

MVP.gif

Figure 1

Conclusion

In this article, I've explained the principles of the Model View Presenter design pattern. Now you have insights to be applied to your architecture decisions.
 

Login to add your contents and source code to this article
share this article :
post comment
 

can i have the demo for mvp design pattern

Posted by tarun agarwal Feb 20, 2012

NIce article John. MVP is very good interface for design pattern.

Posted by Alok Pandey Oct 22, 2011

Welcome back John, after a long time.

Posted by Dinesh Beniwal Oct 22, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor