Click here to Skip to main content
15,791,673 members
Articles / Desktop Programming / Windows Forms

Winforms – Model-View-Presenter – A tutorial

Rate me:
Please Sign up or sign in to vote.
3.59/5 (12 votes)
11 May 2009CPOL4 min read 72.3K   34   18
Winforms – Model-View-Presenter – A tutorial


Coming from C/C++ and diving into .NET, I am constantly surrounded by strange phrases, three letter acronyms and concepts that take a long time to get used to. One of those concepts is the Model-View-Presenter (MVP). There are plenty of articles about MVP around the Web. Most are pointers to Martin Fowler ( or the MSDN ( There are also many articles on CodeProject ( The problem that I have had in the reading of these articles is that most use big $.25 words and unfamiliar phrases that mean nothing to the beginner, along with diagrams that are just plain confusing. Nothing I found that was in plain simple English. After a lot of trial and error and study, I think I finally have something that I can understand. I do not pretend that this is the “right way” or the only way but it works for me.


The goal of using the MVP design pattern is to separate the responsibilities of the application in such a manner as to make the application code:

  • Testable in an automated manner
  • Make the application more maintainable
  • Make the application more extensible

The first bullet means that there are many tools out there in the world that can be used to test code in an automated manner, called “unit testing”. These tools cannot test code that is in form code-behind modules. So the aim is to take that code out of the form code and place it in a DLL that can be tested.

I do not know about anyone else, but for me application code is way more maintainable when it is separated out into modules that have a specific purpose. If some unexpected feature does make it through the unit testing, then you will have a pretty good idea where to look just based on knowing what the various classes’ responsibilities are.

The extensibility part comes in when you have this separation of concerns, adding additional functionality is made easier because the code modules are not closely tied together also known as “loose coupling”.

What Does It All Mean?

The first thing is to understand the meaning of what the terms mean.

View: A view is any form or window that is shown to the user of the application.

Presenter: The presenter is an entity that presents the data to the view that is to be shown to the user.

Model: The model is the actual data that the Presenter will request and gets displayed in the View. The Model is responsible for obtaining the data. So the Model is the one that reads files, or connects to a database or if you are really ambitious, gets the data from a data service object.

The pattern is typically drawn like this.


Looks simple, doesn't it? Well what all those other articles, and examples, didn't tell me was how to turn that simple diagram into a working application.

Get On With It Already!

The first thing to do is to setup the solution. Open up Visual Studio and create a new Windows Forms Application.


Once Visual Studio is through creating your new project, add a class library to the solution to hold all of the various classes. Right click your solution object in the Solution Explorer, select Add then Add new project.



I named mine Common.Lib.dll. You can name yours whatever you want to. I have seen some people that create a class library to contain the business logic and another one to contain the data layer. I think it is overkill for this simple example. Go ahead and delete the Class1.cs file that Visual Studio created for you.

I like to compartmentalize things so I group like classes together. Right click on the class library project; select Add then Select New Folder. Name the new folder, Interfaces. Repeat twice more and name the other two new folders Models and Presenters. Your project should now look like this:


This is the end of Part 1. After starting the article, it quickly grew to 14 pages and I was not done yet so I elected to post a series of pages.

This is the project skeleton so far. Change the extension from .doc to .zip before you open it. This is a workpress requirement.

This article was originally posted at


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

Comments and Discussions

GeneralMy vote of 1 Pin
boussad.yahia13-Sep-10 9:54
boussad.yahia13-Sep-10 9:54 
GeneralLoved it Pin
EliottA21-May-09 12:26
EliottA21-May-09 12:26 
GeneralRe: Loved it Pin
Wes Aday24-May-09 17:27
professionalWes Aday24-May-09 17:27 
GeneralMy vote of 1 Pin
Jay R. Wren20-May-09 8:12
Jay R. Wren20-May-09 8:12 
GeneralRe: My vote of 1 Pin
Wes Aday24-May-09 17:28
professionalWes Aday24-May-09 17:28 
GeneralGood start Pin
Pat Tormey20-May-09 1:34
Pat Tormey20-May-09 1:34 
GeneralRe: Good start Pin
Wes Aday24-May-09 17:33
professionalWes Aday24-May-09 17:33 
Generalnext buzzword - MVP Pin
Thornik13-May-09 0:18
Thornik13-May-09 0:18 
GeneralRe: next buzzword - MVP PinPopular
Wes Aday13-May-09 4:04
professionalWes Aday13-May-09 4:04 
GeneralRe: next buzzword - MVP Pin
wallism19-May-09 15:11
wallism19-May-09 15:11 
GeneralRe: next buzzword - MVP Pin
Pat Tormey20-May-09 1:45
Pat Tormey20-May-09 1:45 
Now let's not make fun of someone's command of English. He's probably an idiot in his own language too..

To the original negative commenter.
The reason you are a getting a negative response to you negative comments is becuase the author is trying to explain something by simplyfying it, and your comments are designed to show off. You are detracting from his effort without adding anything of value to the discussion.

If you can explain it more clearly then point us to your solution..

Pat Tormey
New Hampshire USA
GeneralRe: next buzzword - MVP Pin
Wes Aday24-May-09 17:30
professionalWes Aday24-May-09 17:30 
GeneralRe: next buzzword - MVP Pin
Thornik18-Jun-09 0:54
Thornik18-Jun-09 0:54 
GeneralRe: next buzzword - MVP Pin
Wes Aday18-Jun-09 4:18
professionalWes Aday18-Jun-09 4:18 
GeneralRe: next buzzword - MVP Pin
Thornik18-Jun-09 0:43
Thornik18-Jun-09 0:43 
GeneralRe: next buzzword - MVP [modified] Pin
Wes Aday18-Jun-09 4:27
professionalWes Aday18-Jun-09 4:27 
Generalquestion Pin
Eanna M-annion12-May-09 0:15
Eanna M-annion12-May-09 0:15 
GeneralRe: question Pin
Wes Aday12-May-09 4:12
professionalWes Aday12-May-09 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.