I. Introduction \

The goal of all three is to separate concerns, make the UI easier to transform (from Winform to Webform), and make the UI easier to unit test.

Second, the MVC/MVP


1, the MVC

1. View accepts user interaction requests

2. The View forwards the request to the Controller

3. Controller operates Model to update data

4. When the data is updated, the Model notifies the View of the change

5. View shows the updated data

View and Controller are implemented using Strategy mode, View using Composite mode, and View and Model synchronizing information through Observer mode. The Controller does not know the details of any View, and a Controller can be used by multiple views. One drawback of MVC is that it’s hard to unit test controllers, which manipulate data, but how do you assert changes to that data from the View? For example, clicking on a View button submits an event to the Controller, which modifies the value of Model. This value is reflected in the View as the font and color changes. It’s a little difficult to test this Case.

2, the MVP

1. View accepts user interaction requests

The View forwards the request to the Presenter

Presenter runs the Model to update the database

4. After the data is updated, the Model notifies Presenter that the data has changed

Presenter updates View data

Presenter returns Model changes to the View. Unlike an MVC, a Presenter reacts to a View, unlike a Controller, which passively takes command from the View. Normally, discovery can abstract the View, exposing properties and events, and then Presenter references the View’s abstraction. This makes it easy to Mock the View and improve untestability. Here, the Presenter’s responsibility increases, not only to manipulate the data, but also to update the View.

In reality, MVP implementations vary a bit depending on how verbose a View is. Some tend to place simple logic in a View and complex logic in a Presenter. The other tends to place all logic in presenter. These are called Passive Views and Superivising Controllers.

In Passive View, to reduce the behavior of the UI components, the Controller not only controls the response to user events, but also updates the results to the View. You can test the Controller centrally, reducing the risk that the View will fail.

Controllers in Superivising Controllers both handle user input responses and manipulate views to handle the complex logic of the View.

Three, the M – V – VM

MVVM is to add a ViewModel on the basis of the original domain Model, this ViewModel in addition to the normal properties, but also some properties for the View display. For example, in classic MVPS, a View has a property called IsCheck, and you need to set the View’s IsCheck value in Presenter. In MVVM, however, presenters also have an IsCheck property to synchronize the IsCheck property of a View, and may use Observer mode to synchronize the value of IsCheck. In MVVM, Presenter is renamed ViewModel and becomes what you see as MVVM. MVVM is more popular on platforms that support bidirectional binding. Examples: Microsoft’s WPF and Silverlight.

* Welcome to follow my public account (synchronous update article) * : DoNet technology sharing platform \

Read the original