Click here to Skip to main content
6,306,412 members and growing! (19,671 online)
Email Password   helpLost your password?
Development Lifecycle » Design and Architecture » Application Design     Advanced License: The Code Project Open License (CPOL)

Model View Presenter And Its Best Practices

By santosh poojari

The article describes Model View Presenter Architecture,its Best practices and advantages.
C# (C# 2.0), .NET (.NET 2.0, .NET 3.0), ASP.NET, Architect, Dev, Design
Posted:22 Apr 2008
Updated:5 May 2008
Views:13,353
Bookmarked:35 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
22 votes for this article.
Popularity: 3.14 Rating: 2.34 out of 5
6 votes, 31.6%
1
5 votes, 26.3%
2
1 vote, 5.3%
3
2 votes, 10.5%
4
5 votes, 26.3%
5

Introduction

With the advent of newer technology and framework, architecture design has become very important for development of application.Utilization of the same business functionality across platform based Web application and smart client needs a tactful architecture.Another challenge has been to fit in unit testing framework with the application. MVC failed to achieve this. MVP proved to be boon to achieve this milestone.

MVP vs. MVC

MVP And MVC

Demerits of Model View Controller

  • Unit testing not possible. Websites do not have dll of their own. To achieve this websites need to be converted to web applications.
  • UI tightly coupled with controller and most of the business logic resides in UI.
  • UI contains intrinsic object of .net, thus making unit testing impossible.
  • Work stream distribution is next to impossible.
  • Why MVP ?

  • Work stream distribution for Designer (UI) and Developer.
  • View is decoupled from Presenter and Model (Service & Data Access).
  • This design helps smart client and web application to utilize the common Presenter and Model.
  • Unit testing framework goes well with Presenter.
  • Presenter contains the business logic and the reference of model.
  • Logical Architecture

    Logical Architecture

    Physical Architecture

    Physical Architecture

    Best Practices:

    Data Access Layer

  • Make use of partial class. Assign class name as screen or page level attribute.
    ClientLookupDataProvider.cs
    		partial public class DataProvider
    		{
            }
            
  • Work stream distribution possible across developers.
  • Partial class must have static methods in it.
  • Service Layer

    Logical Architecture

  • Service contains list of all operations which is used by an application.
  • One or more web sites or windows application can utilize these services.
  • Region out each functions for maintenance purpose.
  • Service layer provides an interface which gives access to all data related operations(i.e. from different conventional data sources or by referencing components accessing various data sources).
  • Presenter Layer:

  • Create one BasePresenter which will have all the common attribute across application such as custom exception or initialization of service class.
  •   public class BasePresenter
           {
               public IServiceProvider m_Service=null;
               public BasePresenter()
    		   {
    				m_Service=new Services.ServiceProvider()
    		   }
    		   public void ProcessPresenterLayerException()
    		   {
    		   }
    	  }
    	  
  • Must have public methods and private methods as given below.
  • Public void LoadCustomerList()
    { 
        Ilist customerList = new list(); 
        customerList = GetCustomerList(m_View.CustomerID){}
    } 
    Public void SortCustomerList(){}
    Public void PagingCustomerList(){}
    
    Private IList GetCustomerList(int customerID){}
    
    
  • Public methods exposed to 'View' must not have any return parameter or input parameter.
  • Name public method that relate to UI operation terminology terms.(Load/Populate/Add/Remove)
  • Name private method that relate to back-end operation it actually does such as Get/Insert/Update/Delete
  • Make sure public methods have try catch block while called private methods don’t.
  • Do not make use of intrinsic .net method call .E.g. httpContext.Current.Server.mappath/Server.transfer/server.execute etc.
  • Domain: Business Entity

  • Initialize private members wherever possible.
  • private int _demandID = int.MinValue;
    private string _demandName = string.Empty;
    
  • Make use of parameterized constructor and default constructor. Create cyclic constructor if possible.
  • Public Sample (int a, int b, int c): base (a)
    {
    ……
    }
    public Sample(int a, int b, int c, int d):this(a,b,c)
    {
    ..
    }
    
    

    References

  • http://msdn2.microsoft.com/en-us/magazine/cc188690.aspx
  • http://www.martinfowler.com/eaaDev/uiArchs.html
  • http://blog.vuscode.com/malovicn/archive/2007/12/18/model-view-presenter-mvp-vs-model-view-controller-mvc.aspx
  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    santosh poojari


    Member
    He is a Team Lead currently working with one of the IT company in India.His overall experience in IT field is 6 years. He is a B.E (computers) graduate from Mumbai University.
    His area of Interest is Microsoft Technology : Asp.Net,C#,Web services,SSIS,SSRS,Windows Workflow Foundation 3.0,SQL server 2005,State Machine Compiler,Regular Expression, Enterprise Library3.0,Spring.net,Design Patterns and Architecture Design.He is MCPD-EA Certified.

    http://santoshpoojari.blogspot.com
    Occupation: Team Leader
    Location: India India

    Other popular Design and Architecture articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
    AnswerYeah, yeah, so you can make bullet lists... PinsitebuilderShog911:13 23 Apr '08  
    GeneralRe: Yeah, yeah, so you can make bullet lists... Pinmembersantosh poojari2:16 28 Apr '08  
    GeneralWhy? When compared to Microsoft's MVC PinmemberMike Lang5:37 23 Apr '08  
    GeneralRe: Why? When compared to Microsoft's MVC PinmemberOleg Zhukov7:39 24 Apr '08  
    GeneralNot clear PinadminChris Maunder4:40 23 Apr '08  
    GeneralRe: Not clear PinmemberOleg Zhukov8:49 24 Apr '08  
    GeneralRe: Not clear Pinmembersantosh poojari2:13 28 Apr '08  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 5 May 2008
    Editor:
    Copyright 2008 by santosh poojari
    Everything else Copyright © CodeProject, 1999-2009
    Web18 | Advertise on the Code Project