MV* - alexanderteplov/computer-science GitHub Wiki

MV* Design Pattern

Model View Controller (MVC)

Components

The Model refers to the data and business functionality of the application. This is often represented by a Domain Model where objects are used to model real-world entities and processes by representing their properties and behavior.

The View is the visual representation of the Model and is comprised of the screens and widgets used within an application.

The Controller is a component that responds to user input such as data entry and commands issued from a keyboard or mouse. Its responsibility is to act as a bridge between the human and the application, allowing the user to interact with the screen and data.

In Web applications, the View is the content (generally HTML and associated client-side script) returned to the Web client.

Web-based MVC Controllers process delegated HTTP requests (or information derived from the request depending upon the specific implementation).

Communication

The Model contains no direct link to the View or Controller and may be modified by the View, Controller, or other objects with the system. When notification to the View and Controller are necessary, the Model uses the Observer Pattern to send a message notifying observing objects that its data has changed.

The View and Controller components work together to allow the user to view and interact with the Model. Each View is associated with a single Controller, and each Controller is associated with a single View. Both the View and Controller components maintain a direct link to the Model.

The View’s responsibility can be seen as primarily dealing with output while the Controller’s responsibility can be seen as primarily dealing with input.

Diagrams


Model View Presenter (MVP)

Components

The Model refers to the data and business functionality of the application.

The View is the visual representation of the Model and is comprised of the screens and widgets used within an application.

The Presenter is a component that contains the presentation logic which interacts with the Model.

Communication

Both designs are very similar. The key differences are:

  1. The role of handling user input is moved from Controller to the View in MVP.
  2. The Presenter now is mostly a mediator between View and Model. It encapsulates actions into Commands (see The Command Pattern) so they become revokable.

Diagrams


Model View View-Model (MVVM)

Components

Model refers either to a domain model, which represents real state content (an object-oriented approach) or to the data access layer, which represents content (a data-centric approach).

As in the model–view–controller (MVC) and model–view–presenter (MVP) patterns, View is the structure, layout, and appearance of what a user sees on the screen. It displays a representation of the model and receives the user's interaction with the view (mouse clicks, keyboard input, screen tap gestures, etc.), and it forwards the handling of these to the view model via the data binding (properties, event callbacks, etc.) that is defined to link the view and view model.

View model is an abstraction of the view exposing public properties and commands. Instead of the controller of the MVC pattern, or the presenter of the MVP pattern, MVVM has a binder, which automates communication between the view and its bound properties in the view model. The view model has been described as a state of the data in the model. The main difference between the view model and the Presenter in the MVP pattern is that the presenter has a reference to a view, whereas the view model does not. Instead, a view directly binds to properties on the view model to send and receive updates. To function efficiently, this requires a binding technology or generating boilerplate code to do the binding.

Diagram

Links

⚠️ **GitHub.com Fallback** ⚠️