MVC, MVP and MVVM are three most popular design patterns. Where MVC stands for Model-View-Controller, MVP for Model-View-Presenter and MVVM means Model-View-ViewModel.
All these design patterns by and large help in developing applications that are loosely combined, easy to test and maintain. However, there’s a framework called MVVM cross that allows you to integrate MVVM design pattern to Android and iOS platforms.
MVC, MVP, and MVVM are basically presentation patterns mainly designed to reduce the complex codes in the presentation layer and make the user interface code clutter free, clean and manageable. Let us now understand the difference between these design patterns to know when one should be chosen over the other.
Let us see MVC, MVP and MVVM in details
MVC Design Pattern:
MVC is a software design pattern, introduced in the 1970s. It impels a bifurcation of concerns, which means domain model and controller logic are separated from the user interface (view). As a result maintenance and testing of the application becomes simple and easy. MVC design pattern divides an application into three major aspects: Model, View, and Controller.
Model:
The Model represents a collection of classes that explains the business logic i.e. business model and the data model (data access operations). It also defines the business rules for data means as how the data can be altered and manipulated.
View:
The View represents the user interface components such as CSS, jQuery, HTML, etc. View displays the data that is received from the controller as the outcome. This also changes the model(s) into the user interface.
Controller:
The responsibility of the Controller is to process incoming requests. It gets the input from users via the View, then processes the user’s data through the Model, passing back the results to View. It normally acts as a mediator between the View and the Model.
MVP Design Pattern:
The MVP pattern is similar to the MVC pattern, wherein the controller is replaced by the presenter. This pattern divides an application into three major aspects: Model, View, and Presenter.
You can see : Android MVP Pattern Example
Model:
The Model represents a collection of classes that explains the business model and the data model. It also defines the business rules for data means as how the data can be altered and manipulated.
View:
The View represents the user interface components such as CSS, jQuery, HTML, etc. View displays the data that is received from the controller as the outcome. This also changes the model(s) into the user interface.
Presenter:
The Presenter is responsible for addressing all user interface events on behalf of the view. It receives input from users via the View, then process the user’s data through the Model that passes the results back to the View. The View and the Presenter are completely separated, unlike View and Controller, from each other and communicate to each other by an interface. The Presenter also doesn’t handle the incoming request traffic like controller.
See this : Top 10 Programming Architectural Patterns
MVVM Design Pattern:
MVVM pattern supports two-way data binding between View and ViewModel. This allows automatic propagation of changes, inside the state of ViewModel to the View. Generally, the ViewModel utilizes the observer pattern to inform changes in the ViewModel to the Model.
Model:
The Model represents a collection of classes that explains the business model and the data model. It also defines the business rules for data means as how the data can be altered and manipulated.
View:
The View represents the user interface components such as CSS, jQuery, HTML, etc. View displays the data that is received from the controller as the outcome. This also changes the model(s) into the user interface.
ViewModel:
The View Model is responsible for displaying methods, commands, and other functions that assist in maintaining the state of the View, manipulating the Model as the result of actions on the View, and triggering the events in the View itself.
What you think?
Today, the MVC pattern is used by well-known frameworks such as Ruby on Rails, Apple iOS Development, ASP.NET MVC, etc. While MVP is mostly used for ASP.NET Web Forms applications and MVVM is used by WPF, Caliburn, Silverlight, nRoute, and more. Which development pattern are you currently using in your software projects? Let us know in the comments below.
Share your thoughts