I had a request from one of my blog’s reader (Bastien) that I can’t skip. Last week he asked me to write a short article on how to implement the Model View Presenter with Windows form. So let’s skip for a while my series of articles about Prism and let’s see what is the MVP and how it should be implemented.
The Model View Presenter pattern.
The definition of the model view presenter pattern can be found in many web site, let’s use the classic definition provided by MSDN. (This is an interesting article that explains the MVP).
Model-view-presenter (MVP) is a user interface design pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic.
1) The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
2) The view is an interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
3) The presenter acts upon the model and the view. It retrieves data from repositories (the model), persists it, and formats it for display in the view.
There are two different types of MVP implementation: the MVP passing view and the MVP supervising controller. The main difference from these two types of UI patterns is that in the passive view, the view doesn’t know anything about the model and the presenter is in charge of “advise the view” that something happened. In the second implementation, the view knows the model for the basic binding and the presenter is used only when the view requires complex UI manipulation.
Personally I completely disagree with the second approach, because the layers are not really recyclable, and a change in the model constraint the developer to change also the view …