Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Mvvm mode

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what is Mvvm mode". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Brief introduction of 0x01 MVVM mode

MVVM is the abbreviation of Model, View and ViewModel. The introduction of this mode is to use ViewModel to reduce the coupling between View and Model, that is to say, to reduce the coupling between View and Model. It can also be said to reduce the coupling of interface and logic. Ideally, the interface and logic are completely separated. When changing the interface unilaterally, there is no need to change the logic code, and the same logic code does not need to change the interface. The same ViewModel can be displayed using a completely unused View, and the same View can use different ViewModel to provide different operations.

1.Model

Model is a class, which is the abstraction of real things. All the things involved in the development process can be abstracted as Model. For example, the customer's name, number, phone number, address and other attributes also correspond to the Property in class, and the customer's behavior of placing orders, paying and so on corresponds to the methods in class.

2. View

View is easy to understand, which is the interface.

3. ViewModel

Model abstraction is mentioned above, so ViewModel is an abstraction of View. The data displayed corresponds to the Property in ViewMode, and the command executed corresponds to the Command in ViewModel.

Decoupling method of MVVM in 0x02 WPF

In WPF's MVVM mode, the association of data and commands between View and ViewModel is achieved through binding, and there is no direct dependency between View and ViewModel after binding. Specifically, when there is a data change in View, you will try to modify the binding target. Similarly, when View executes a command, it also looks for the bound Command and executes it.

In turn, when Property changes, ViewModel will send a notice saying, "the Property named XXX has changed, and so will any of you View who have bound XXX!" and it doesn't care whether the View has been received or not. It is even easier for Command in ViewModel to break away from View, because when Command manipulates the data during the operation, it does not need to manipulate the data in View at all, it only needs to operate the Property in ViewModel, and the changes in Property can be reflected on the View through binding. This also eliminates the need for View to participate in testing Command. This is also the so-called data driver that I didn't understand at all when I first came into contact with WPF.

In this way, ViewMode can be tested without View at all, and View can be tested without ViewModel at all (just testing interface layout and business-independent content such as animation, of course).

Problems to be solved in 0x3 MVVM Framework

You can see from the figure that if you want to implement a MVVM framework, the most basic problems that need to be solved are data binding and command binding. In addition, because a large number of events are generated in UI, you also need to bind events to commands in MVVM. Later articles will try to solve these problems in turn. Finally, I would like to say that any design pattern is a reference, there are use scenarios, do not copy mechanically. In the actual development, a more adaptable mode should be adopted according to the characteristics of the project.

This is the end of the content of "what is Mvvm Mode". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report