by Marius Gheorghe
13. April 2007 19:14
I have decided to write some posts on Model Viewer Presenter. If you don't know, Model Viewer Presenter ( MVP from now one for the sake of my fingers) is a pattern which , among other things, "dictates" how to separate logic from UI. You can think of it as a way to "implement" separation of concerns. Here are the MVP pieces:
- Model : this is you business object.
- View : this is the UI object (Windows/Web form, PocketPC window etc)
- Presenter (or "the glue") : this is the object which gets the data from the model, modifies it and passes it to the view.
One of the things for which MVP is touted is "presenter reusability". Write you presenters correctly, they say, (without referencing the View from the Presenter) and , when you port the application from other platforms, you just need to rewrite the view. Personally i think that's wrong ( in the sense that you won't need this). Web applications are different from desktop applications which are different from mobile applications. If you "port" a application from a platform to another this "presenter reusability" thingie won't hold.
Here is an example :
Shopkeeper is a MVP web application.
Also here is the "port" to the desktop platform (a smart client application)
The web application has 10 views/presenters. The desktop application has....3 views/presenters. Yeap...that's right. That functionality was encapsulated, in the case of the desktop application, in just 3 views/presenters.
Conclusions :
- platforms are different (suprise heh ?!)
- use MVP for what it really is. The best way to enforce separation of concerns.