Model View Presenter
Martin Fowler has introduced several new enterprise patterns for his new book. The one that has intrigued me the most so far is Model View Presenter.
Model View Presenter separates the behaviour of a presentation from the view while allowing the view to receive user events.
Take the code below as an example:
public interface IMyView { string FirstName { get; set; } string LastName { get; set; } string FullName { get; set; } } public class MyPage1 : System.Web.UI.Page, IMyView { IMyView.FirstName { get { return txtFirstName.Text; } set { txtFirstName.Text = value; } } IMyView.LastName { get { return txtLastName.Text; } set { txtLastName.Text = value; } } IMyView.FullName { get { return fullNameLabel.Text = value; } set { fullNameLabel.Text = value; } } void btnButton_Click(object sender, EventArgs e) { // this would probably be a class level declaration // so that it is not recreated every time. In this trivial example, // it doesnt matter MyPresenter presenter = new MyPresenter(this); presenter.CreateFullName(); } } public class MyPresenter { private IMyView view; public MyPresenter(IMyView view) { this.view = view; } public void CreateFullName() { view.FullName = String.Format("{0} {1}", view.FirstName, view.LastName); } }
At this point, the Concrete View contains all the UI widgets. Since we do not have any UI components in our View interface, this would make the view and the presenter truly portable.
All of our business logic is contained in the Presenter. We could take the Presenter and the IMyView interface and create a winforms application just as easily. Even better, since we’ve completely abstracted the view and made it as dumb as possible, we could easily test our application as well.
Since we’re using Constructor Injection (Type 3 Inversion of Control), we can easily create a MockView that derives from IMyView that merely contains accessor variables for the properties. Our test then passes the MockView object into the MyPresenter object. With that, we’re able to completely test the presenter.
I’m looking forward to investigating this pattern more, and hope to show a working sample using this pattern soon.
No, he’s not. You’re describing MVC (Model View Controller).
From the link:
Classic MVC doesn’t work well with modern rich client tools because they design things so that the view handles all the user events such as mouse and keyboard clicks. In Model View Presenter the view continues to handle these, but then immediately delegates these to the presenter. The presenter then decides what to do with the event, communicating with the domain and the data in the view’s controls.
The difference between MVP and class MVC is that in MVC the Controller changes the Model or the View and the View gets data from the Model. The model also updates the view when data changes.
Using MVP, the View only communicates with the Presenter. The presenter then communicates with both the View and the Model.
what about a command within the model view presenter?
http://mragile.spaces.live.com/blog/
Great article,
Implementation gives a simple understanding :),
At first I had doubts with this pattern, but after gaining a deeper understanding of it I’ve realised how it enforces separation of view from model(controller). makes the view dumber which is a good thing.
Cheers
Sonny M
Instead of calling methods on the presenter from the view, i find that defining events in the view interface makes for a more clean cut (the view no longer has to have knowledge of the presenter).
I the add the view to the presenter via constructor injection:
ICustomerView customerView = new CustomerForm();
CustomerPresenter customerPresenter = new CustomerPresenter(customerView);
Inside the presenter i then hook up the events that the presenter needs from the view.. (e.g. “Save”)

Martin Fowler did not introduce this pattern as his did he? This is a fairly old pattern taught in design architecture classes in CS programs everywhere.
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLD,GGLD:2004-29,GGLD:en&q=model+controller+pattern