September 12, 2018

Overview of MV* design patterns MVC MVP MVVM

Over the years many design patterns have emerged to enforce separation of concerns in code bases. The MV* patterns have found use in server side technology such as Java EE and Dot Net as well as on browser in some modern libraries. Here we attempt an overview of these patterns.

The MV* patterns have three separations: Model, View and the Glue. The interaction between separated model and the view is facilitated by the Glue, which goes by name of Controller, Presenter or ViewModel. Hence the pattern Model-View-Controller (MVC), Model-View-Presenter (MVP) or Model-View-ViewModel (MVVM).

Model is the encapsulation of business data and logic. This contains the internal representation of the data relevant to the software. It contains business logic, which is the processing of data in order to achieve desired function of the software. It is not concerned with how that information is laid out on the user interface or formatting thereof.

View is the encapsulation of visual aspects of data being presented to user on user interface. This means layout, formatting, effects rendered to the user. It is not concerned about how the data is stored and processed internally for achieving desired functionality of software.

MVC has Controller as the glue. The controller is responsible for receiving user input. After receiving user input it interacts with model to update it. After that the model notifies the view that now it is ready to render. View renders the data and sends it to the user.

The separation of model from view allows testing of model independently from the view. However, the controller is tied to the view and can contain some processing which is not easy to test.

MVP has Presenter as the glue. The presenter is obtains input from the view and then interacts with model to update it. The results are fetched from model and presenter then updates the view.

The View in MVP does not contain any processing for display. Processing is shifted to the presenter. This allows testing of presenter and model easily.


MVVM has ViewModel as the glue. In practice, MVVM relies on a "data binding". Data binding automatic synchronization of data in view to data in viewmodel. ViewModel is responsible for updating the model.

The binding in MVVM reduces boilerplate code required. Without platform support for binding, Implementing MVVM requires much more effort.

MVC, MVP and MVVM has their own applications. All are used in various software frameworks which are popular today.

No comments:

Post a Comment