.netC#.net

MVC, MVP and MVVM Design Patterns

In this article, we will discuss on 3 most important design patterns for software development.

  • MVC Design Pattern
  • MVP Design Pattern
  • MVVM Design Pattern

MVC Design Pattern:

 

  • MVC stands for Model-View-Controller. It is a software design pattern which was introduced in 1970s.
  • MVC design pattern splits an application into three main aspects: Model, View and Controller
    • A controller can send commands to the model to update the model’s state. It can also send commands to its associated view to change the view’s presentation of the model
    • A model stores data that is retrieved according to commands from the controller and displayed in the view.
    • A view generates an output presentation to the user based on changes in model
  • In MVC, the model and controller logic are decoupled from user View

ASP.net MVC

 

Model:

The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View:

The view manages the display of information.

Controller:

The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

Model-View-Controller is a fundamental design pattern for the separation of user interface logic from business logic.

It is important to note that both the view and the controller depend on the model. However, the model depends on neither the view nor the controller. This is one the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation

 

MVP Design Pattern:

 

MVP is a user interface architectural pattern facilitate automated unit testing and improve the separation of concerns in presentation logic

  • The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
  • The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
  • The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.
    Normally, the view implementation instantiates the concrete presenter object, providing a reference to itself
  • User interacts with the View.
  • There is one-to-one relationship between View and Presenter means one View is mapped to only one Presenter.
  • View has a reference to Presenter but View has not reference to Model.
  • Provides two way communication between View and Presenter.

MVP Design Pattern

 

Model
The Model represents a set of classes that describes the business logic and data. It also defines how the data can be changed and manipulated.
View
The View represents the UI components. It is only responsible for displaying the data that is received from the presenter as the result. This also transforms the model(s) into UI.
Presenter
The Presenter is responsible for handling all UI events on behalf of the view.

This receive input from users via the View, then process the user’s data with the help of Model and passing the results back to the View.

Unlike view and controller, view and presenter are completely decoupled from each other’s and communicate to each other’s by an interface.
Also, presenter does not manage the incoming request traffic as controller

MVVM Design Pattern:

 

  • MVVM stands for Model-View-View Model.
  • This pattern supports two-way data binding between view and View model.
  • This enables automatic propagation of changes, within the state of view model to the View
  • User interacts with the View.
  • There is many-to-one relationship between View and ViewModel means many View can be mapped to one ViewModel.
  • View has a reference to ViewModel but View Model has no information about the View.

MVP Design Pattern

Model
The Model represents a set of classes that describes the business logic and data. It also defines how the data can be changed and manipulated.
View
The View represents the UI components. It is only responsible for displaying the data that is received from the presenter as the result. This also transforms the model(s) into UI.
Presenter
The Presenter is responsible for handling all UI events on behalf of the view.

This receive input from users via the View, then process the user’s data with the help of Model and passing the results back to the View.

Unlike view and controller, view and presenter are completely decoupled from each other’s and communicate to each other’s by an interface.
Also, presenter does not manage the incoming request traffic as controller

© 2015, www.techkatak.com. All rights reserved.