This article mainly introduces the MVVM mode ViewModel and view, model what is the difference? This article explains their function and function respectively, then summarizes the difference between them, the need for friends can refer to the following
Model: Very simple, is the business logic related to the data objects, usually from the database mapping, we can say that the corresponding model of the database.
View: Also very simple, is the display of the user interface.
Basically, most of the software does nothing more than read data from the data store, show it to the user interface, and then receive input from the user interface and write to the data store. So, for data storage (model) and interface (view) These two layers, we basically have no objection. However, different people have different opinions on how to show the model to view and how to write the data from view to model.
The MVC idea is that every change in the interface is an event, and I just need to write a bunch of code for each event to convert the user input into the object in model, which can be called Controller.
And MVVM's view is that I give the view inside a variety of controls also define a corresponding data object, so as long as the change of the data object, view inside the content will automatically refresh, and in the view of any operation, the data object also follow automatic Update, so much beauty. So:
ViewModel: Is the model that corresponds to the interface (view). Because the database structure is often not directly related to the interface control one by one, you need to define a data object specifically corresponding to the control on the view. And ViewModel's job is to encapsulate the model object into an interface data object that can display and accept input.
As for the ViewModel data automatically refreshed with the view, and synchronized to the model, this part of the code can be written as a common framework, without the programmer to worry about themselves.
Simply put, ViewModel is the view and model connector, view and model through ViewModel to achieve two-way binding.