This article mainly introduces the differences between ViewModel and View and Model in MVVM mode? This article explains their functions and functions, and summarizes the differences between them. For more information, see
Model:It is very simple, that is, the data objects related to the business logic, usually mapped from the database. We can say it is the model 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:Is the Model 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.
Simply put, ViewModel is the connector between View and Model. View and Model are bidirectional bound through ViewModel.