What is the difference between mvc and mvvm ?, What is the difference between mvcmvvm?
Source: https://segmentfault.com/q/1010000000534091? _ Ea = 178721
Model: Very simple, it is the data objects related to the business logic, which are usually mapped from the database. We can say thatModel corresponding to the database.
View: It is also very simple, that is, the displayed user interface.
Basically, most software simply reads data from data storage, presents the data to the user interface, receives input from the user interface, and writes it to the data storage. Therefore, there is almost no objection to the two layers of data storage (model) and interface (view. However, different people have different opinions on how to present the model to the view and how to write data from the view to the model.
In MVC's opinion, every change on the interface is an event. I only need to write a bunch of code for each event, to convert user input into objects in the model. This heap of code can be called controller.
In MVVM's opinion, I defined a corresponding data object for various controls in the view, so that as long as the data object is modified, the content displayed in the view will be automatically refreshed, in view, the data object is automatically updated after any operation. Therefore:
ViewModel: YesModel corresponding to the interface (view). Because the database structure often cannot correspond to interface controls one by one directly, you need to define a data object to correspond to the controls on The view. ViewModel encapsulates the model object into interface data objects that can display and accept input.
As for the viewmodel data, as the view is automatically refreshed and synchronized to the model, this part of the code can be written as a public framework, so you don't have to worry about it yourself.