MVC
stands for Model, View, Controller, and MVP
pattern is evolved from MVC
pattern. By cleverly separating the view and the model through the presenter, the MVP
pattern changes the name of the Controller
to Presenter
and also changes the direction of communication. The MVP
pattern does not belong to the category of the generally defined 23
design patterns, rather it is usually considered as a broadly defined architectural design pattern.
In MVC
, the View
can directly access the data in the Model
, but in MVP
, the View
cannot directly access the Model
. Instead, it provides an interface for the Presenter
to update the Model
, and then updates the View
through observer pattern, etc. Compared with MVC
, the MVP
pattern decouples the View
and Model
, completely separating the view and the model, making the division of responsibilities clearer. Because the View
does not depend on the Model
, the View
can be separated and made into a component, only needing to provide a series of interfaces for upper layer operations.
Here we mainly illustrate the layered structure of MVP
. To implement the transmission of information in MVP
, some parsing of commands and events is needed. The Presenter
, as the middleman between View
and Model
, needs to manually synchronize the data from View
to Model
and from Model
to View in addition to basic business logic. For example, if we implement a
++ counter in the
View, we need to carry out specific operations in the
Presenter to
++ the
Model, and then
Render it to the view. Furthermore, due to the lack of data binding, if the
Presenter has more requirements for view rendering, it has to pay too much attention to specific views. Once the view requirements change, the
Presenter` also needs to change.