In-depth discussion of mvc mvp mvvm and mvcmvvm
After reading "Android advanced light" and "Android source code design mode", I have a deeper understanding of mvc mvp mvvm. Next, I will explain the characteristics of the three in Android in vernacular, if there are any mistakes, I hope you will criticize and correct them.
1. MVCOrganize code by separating business logic, data, and interface display.
Model: The data that corresponds to the data part and accesses the data (including the data obtained from the database and the network)
View: displays the corresponding interface and responds to User Interaction Events (View depends on Model)
Controller: process the logic of user interaction events. It is generally responsible for reading data from the view and then sending data to the model.
Disadvantage: coupling of Model and View
View corresponds to a layout file, which does very little.
Activity is like a View and a Controller. It not only processes Data Binding operations in the layout file but also the Event Logic.
2.MVP
Model: The data that corresponds to the data part and accesses the data (including the data obtained from the database and the network)
View: it corresponds to Activity and is responsible for drawing and interacting with users.
Presenter: completes the interaction between views and models and processes business logic. (There is a Presenter in the View, and the Presenter interacts with the View through the interface)
Advantage: reduced Activity responsibilities and simplified Activity code. view and model layers are no longer completely decoupled from each other, and complicated logic code is extracted to the Presenter for processing.
The following figure compares MVC and MVP:
3.MVVM
It does not seem to be much different from MVP, except that the presenter layer is changed to the viewmodel layer, and the view layer and viewmodel layer are mutually bound, this means that when you update the data in the viewmodel layer, the view layer changes the ui accordingly..