Model View Presenter: Control Model

When you use the Model View Presenter (MVP) Pattern you design by contract. One of the contracts you specify is the contract which describes the graphical interface, called the view. Normally you will specify the contract with base types such as Strings and Booleans. I want to show you another way to define the view by using contracts specifying controls.

Martin Fowler called for the retirement of the MVP Pattern in July 2006 and suggested to separate the pattern into two new patterns, namely ‘Supervising Controller‘ and ‘Passive View‘. This blog-posting is not intended to explain the basics of the MVP-pattern. That being said, I even expect the reader to have a certain level of familiarity with the pattern.

The ‘Passive View’ is a pattern in which the User Interface has as less logic as possible. I prefer the ‘Passive View’ above the ‘Supervising Controller’ because lesser logic makes it easier to substitute the user interface with a new one. I use the Passive View as the pattern of choice and when I talk here about the MVP pattern I am referring to the Passive View approach.

As said above, classic MVP models the interface which describes the GUI (view) with Strings, Booleans and perhaps some domainobjects. When you want a grid in your GUI you will specify a List<object> in your view interface. Then in your implementation of the view you will have to write some logic to put the list of objects into the grid.
This approach has two major downfalls. The first is the amount of logic you have to put in your implementation. I am a big fan of the Passive View because the lack of logic in the implementation of the view makes the view easy to replace. The second downfall is that the logic you write in the implementation has to be written over and over again in the different forms and applications you create.

To avoid this two downfalls I am suggesting a different way of modeling the view using contracts of controls. I would like to call it the ‘Passive View Control Model’. Instead of specifying that the view should have a string to get the username given by a user in a textbox I tell the view to have a ITextbox for the username, which could be a WinForms Textbox or a ASP.NET Textbox.

Let me clarify myself in an example on the next page.

  1. Thank you for sharing your thoughts!

    I am definitely looking forward to the next posts about MVP and how you plan to solve the issues concerning internationalization of labels and error messages. I also would like to see a sample of how you plan to use a grid, or am I too greedy now (pun intended) ;-)


  1. No trackbacks yet.