Understand MVC, MVP and MVVM

Time:2022-4-18

MVC is the model – View – controller, MVP is the model – View – presenter, and MVVM is the model – View – ViewModel. We can see that the three are similar and can be regarded as the data – View – control layer. What are the differences between the three?

MVC is actually a model processing data. The controller is responsible for processing logic, sending the model data to the view, and the view is responsible for updating the display data;

MVP takes presenter as the core, and presenter can be seen that controller is divided into view + presenter, and view and view are merged. Presenter exposes API to controller and calls to realize the connection between controller and view to realize response and data update. The difference between MVC and MVC is the decoupling between view and controller. View and presenter are realized through protocol.

MVVM decouples all three and realizes two-way binding. It is realized through observer mode. ViewModel monitors view and model, and notifies view to update data when model data is updated;

MVC, MVP and MVVM personally understand that the relationship between the three is actually a decoupled advanced level, but the less the relationship between data, view and control layer, the more complex it is, the less the coupling degree of the more complex architecture is, but the slower the development speed is, so we should choose the appropriate architecture for development according to our own project requirements.

Recommended Today

MySQL related

Indexes Bottom structure Disadvantages of hash table index: Using hash storage requires adding all files to memory, which consumes more memory space If all queries are equivalent queries, the hash is indeed fast, but in the actual scene, more data is found, and not all queries are equivalent queries, so the hash table is not […]