This is the 27th day of my participation in Gwen Challenge

The MVVM pattern

MVVM mode, model-view-viewModel. The MVVM pattern is also an enhanced version of the MVC pattern, abstracting the state and behavior of the View, separating the View UI from the business logic. The core of MVVM is data-driven ViewModel, which also acts as a bridge between View and Model. The ViewModel handles the Model data objects to make the data easier to manage and use.

Architectural layering

Model

The capabilities and responsibilities of the model layer and the MVC pattern are the same: add, delete, modify and review the data, and the data model stores the data.

View

Similarly, the view layer has been introduced in MVC mode and MVP mode. Responsibility is used to display UI interface and respond to user interaction, and is responsible for corresponding feedback results after sending events, which exist in a form understandable to user interaction.

ViewModel

ViewModel is an important layer of MVVM pattern, which is different support for MVVM pattern and MVC pattern, as well as the core idea of MVVM pattern. The MVC pattern Controller becomes bloated and difficult to maintain as more and more business is developed and systems become more and more complex. MVVM mode uses ViewModel to separate data and logical processing parts for separate management. In MVVM mode, VM does not replace C, but separates business logic from business operation. View operation business is still kept in C, and complex business data logic and processing process are completed by VM.

Two-way binding

Two-way data binding common front-end development, such as a variable value, through the input box input value assigned to the variable needs to set a listener for the input box; Each time the value of the input box changes, the value is assigned to the variable by the listener; When an external operation changes a variable, the input field needs to be renumerically processed. With bidirectional binding, the variable value can be synchronized to the input box when the external operation changes, and the input value of the input box can be assigned to the variable in time. The principle of two-way binding in real time can be understood as the publisher – subscriber pattern

Such as Vue front-end framework to achieve two-way data binding function, do not need developers to achieve real-time update data, as long as the framework style code can be simple to achieve.

reference

  • Android Source Code Design Patterns
  • Vue