What is the difference between ViewModel and view and model in MVVM mode?

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.