Mvvm is short for Model-View-viewmodel.

Source: Internet
Author: User
Address: http://baike.baidu.com/view/3507915.htm

Mvvm is short for Model-View-viewmodel.

Microsoft's WPF brings new technical experiences, such as sliverlight, audio, video, 3D, and animation ......, This makes the software UI Layer more detailed and customizable. At the technical level, WPF also brings new features such as binding, Dependency Property, routed events, command, datatemplate, and controltemplate. The origin of the mvvm (Model-View-viewmodel) Framework is a new architecture framework that evolved from the combination of the Model-View-presenter model and WPF. It is based on the original MVP framework and integrates the new features of WPF to cope with the increasingly complex demands of customers.

The combination of WPF Data Binding and presentation model is a good practice, which allows developers to separate view and logic. However, this data binding technology is very simple and practical and also unique to WPF, so we call it Model-View-viewmodel (mvvm ). This mode is similar to the classic Model-View-presenter mode. In addition to a model tailored to the view, this model is the viewmodel. Viewmodel contains all the UI-specific interfaces and attributes, and is bound to the attributes of a viewmodel view. The loose coupling between the two can be obtained. Therefore, you need to write the correspondingCode. The data binding system also supports validation of input errors transmitted to the view in a standardized manner.

A view is usually An ASPX page. In previous design patterns, due to lack of clear division of duties, the UI Layer often becomes the all-around proxy of the logic layer, while the latter actually belongs to other layers of the application. The m in MVP is actually a model that encapsulates the computing relationship between core data, logic, and functions, and the M in MVC is a view (form ), P encapsulates all operations in the form, and responds to user input and output, events, and so on. It is similar to C in MVC. The difference is that MVC is a system-level architecture, MVP is used on a specific page. That is to say, MVP is much more flexible than MVC, and its implementation is extremely simple.

We will analyze it from the iview interface layer, which can help us decouple various UIS from the logic layer, and at the same time enter the automation test (Unit/automation test) from the UI Layer) the portal is provided. In the past, the UI that can be compiled by winform, web form, and MFC communicates with the iview layer through event Windows messages. The best way to communicate with the iview layer is to use binding. Of course, you can also use events. To implement iview In the presenter layer, the polymorphism mechanism ensures that the UI Layer displays appropriate data during runtime. For example, bindingProgramYou may see that the binding source is a variable of the interface type. In fact, the object referenced by this interface variable is the real data source.

The MVC pattern is very familiar to everyone. I will not repeat it here. These pattern also evolved in turn to form MVC-> MVP-> mvvm. One sentence is good: when an object is relayed, any interface is the easiest place to be torn down. Therefore, iview serves as a layer of Common View Interface constraints (contracts), while view can convey a layer of decoupling.

The following describes the mvvm design mode. Because of the emergence of WPF technology, the MVP design mode is improved. The mvvm mode uses the data binding infrastructure. They can easily build the necessary elements of the UI.

See the Composite Application Guidance for WPF (PRISM)

The view is bound to the viewmodel, and some commands are executed to request an action from it. In turn, the viewmodel communicates with the model and tells it to update to respond to the UI. This makes it easy to build the UI for the application. The easier it is to paste an interface to an application, the easier it is for the designer to use blend to create a beautiful interface. At the same time, when the UI and functions become increasingly loosely coupled, the functional testability is getting stronger and stronger.

In MVP mode, designers add an interface between the UI Layer and the logic layer to enable the UI Layer to be separated from the logic layer. Both UI developers and data developers must respect this contract and follow it for design and development. In this way, the same set of data logic can be used in both web UI and window UI. Learn from MVP's iview layer to develop habits. View model sounds more appropriate than presenter. It puts some events and commands in controler.

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.