Model Views: MVP, MVC, MVVM design patterns
A presenter calls methods of a view to update the information that the view displays.
The view exposes its methods through an interface definition, and the presenter contains
a reference to the view interface. This allows you to test the presenter with different
implementations of a view (for example, a mock view).
MVP vs MVC (Model View Controller)
So what really are the differences between the MVC versus MVP pattern. Actually there are not a whole lot of differences between them. Both patterns focus on separating responsibility across multi components and promote loosely coupling the UI (View) from the business layer (Model). The major differences are how the pattern is implemented and in some advanced scenarios you need both presenters and controllers.
Here are the key differences between the patterns:
- MVP Pattern
- View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.
- Easier to unit test because interaction with the view is through an interface
- Usually view to presenter map one to one. Complex views may have multi presenters.
- MVC Pattern
- Controller are based on behaviors and can be shared across views
- Can be responsible for determining which view to display (Front Controller Pattern)
Hopefully you found this post interesting and it helped clarify the differences between the MVC and MVP pattern. If not, do not be discouraged patterns are powerful tools that can be hard to use sometimes. One thing to remember is that a pattern is a blue print and not an out of the box solutions. Developers should use them as a guide and modify the implementation according to their problem domain.
Good diagrams: http://ameleta.spaces.live.com/blog/cns!5F6316345A821420!163.entry?sa=431249794
WPF introduces the MVVM pattern (Model View ViewModel)
WPF has changed a few things:
- through declarative programming (i.e. XAML) a lot of plumbing is created for you which especially in the context of databinding saves a lot of code. Another area is e.g. animations and styling; what previously had to be programmed in C# is now possible inside XAML through triggers or events.
- in the MVC pattern the View is presenting the data from the Model but now XAML does this job and sometimes need things like value converters or the ObservableCollection to update the presentation
- user controls in WPF allow you to define a default generic.xaml style which can be overriden when used inside an application, i.e. styling of existing controls is a new feature which adds flexibility to the presentation of the Model
- XAML allows a wide variety of mechanisms to change things or to react to user actions; through the ICommand that is now defined in the framework, through triggers in XAML, through animations, through event bubbling or tunneling (which is also new)
Monday, January 12, 2009 5:06:17 PM