Difference between MVC, MVP And MVVM
Difference between MVC, MVP And MVVM
MVC, MVP, and MVVM are some of the common patterns to guide programmers toward creating decoupled solutions.
The software behaviors that are common to MVC, MVP, and MVVM are:
1)Data Layer / Business Logic (Model): This is the behavior which applies the business logic to the application’s data. A Domain Model usually represents the Model where the objects are used to mimic the real world entities.
2) Presentation Layer / UI ( View ): View is responsible for the visual presentation of the application. This behavior displays model information to the user.
3) Application Logic ( Controller, Presentation or View Model ): This behavior holds the logic that implements the interaction between the model and the view.
- MVC consists of three layers Model, View, and Controller.
- MVC is a compound pattern
- It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure.
- It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
- It provides better support for test-driven development (TDD).
- It works well for Web applications that are supported by large teams of developers and for Web designers who need a high degree of control over the application behavior
- Client-side library: Backbone.js, knockback.js, Spine.js, angular.js.
- Server-side library: ASP.NET MVC, Spring MVC,Ruby-on-Rails
- MVP consists of three layers Model, View, and Presenter.
- In MVP, View and Model are more loosely coupled, providing a clearer separation of concerns.
- MVP, View is responsible for delegating the user input to the Presenter.
- MVP, Presenter and View should have a 1-1 relation, with each View having a reference to its Presenter through the interface.
- MVP, view binds to the Model directly through data binding.
- In MVP, unit testing is easier, as View knows Presenter through an interface which can easily be mocked.
- Client-side library:Riot.js,GWT
- Server-side library: Classic ASP.NET,JSP Servlets.
- MVVM pattern is a one of the best solutions to handle such problems for WPF and Silverlight application.
- When you use MVVM pattern for WPF, Silverlight the view wouldn’t have the typical event handlers that’s so common in UI code.
- MVVM provides a clear separation between the UI and application logic.
- Client-side library:Knockout.js, Kendo (MVVM)
- Server-side library:WPF (Desktop) or Silverlight,Windows Phone apps (XAML),Adobe Flex
- The MVVM pattern includes three key parts:
- Model (Business rule, data access, model classes)
- View (User interface (XAML))
- ViewModel (Agent or middle man between view and model)
When to use which?
- Use in situations where binding via a datacontext is not possible.
- Windows Forms is a perfect example of this. In order to separate the view from the model, a presenter is needed. Since the view cannot directly bind to the presenter, information must be passed to it view an interface (IView).
- Use in situations where binding via a datacontext is possible. Why? The various IView interfaces for each view are removed which means less code to maintain.
- Use in situations where the connection between the view and the rest of the program is not always available (and you can’t effectively employ MVVM or MVP).
- This clearly describes the situation where a web API is separated from the data sent to the client browsers. Microsoft’s ASP.NET MVC is a great tool for managing such situations and provides a very clear MVC framework.