MVC and MVVM understand
MVC and MVVM look similar, but in fact there is a difference, just like two villas, villas look like that on the surface, no one is more than a few chimneys, but the biggest difference is that the “butler” in the villa is different. Different people in charge have different ways of doing things and different procedures. As the old saying goes: You go your way, I’ll go mine. You walk on your feet, I’ll walk in a car. No matter what you do, just go.
1 MVC
- MVC is Model View Controller
- In simple terms, the controller controls the model layer data and returns it to the View layer for display. What the controller performs here is the role of “housekeeper” in the villa.
- View accepts user interaction requests
- The View passes the request to the Controller for processing
- Controller operates Model to update and save data
- After the data update is saved, the Model notifies the View of the update
- View updates the changed data to the user for feedback
2 MVVM
- MVVM is Model, View, ViewModel (Model-view-viewModel), ViewModel is the “housekeeper” of this villa of MVVM.
- Abstracting the state and behavior of the View allows us to separate UI from business logic.
- The advantages of MVVM are low coupling, reusability, and independent development.
- View receives user interaction requests
- The View passes the request to the ViewModel
- ViewModel performs Model data updates
- Notifies the ViewModel that the data has changed after the Model updates the data
- ViewModel Updates View data
3 the differences
The MVVM pattern is somewhat similar to MVC, with the following differences
- The ViewModel replaces the Controller, below the UI layer
- The ViewModel exposes the View to the data and instruction objects it needs
- The ViewModel receives data from the Model
In a nutshell, MVVM evolved from MVC to map data from the Model to the View by adding a non-visual component on top of the Model but underneath the View.
A simplified understanding of extensibility is: In some extent, MVVM is a MVC apprentice, from in MVC, teacher and pupil both have the same technology, in certain cases, the disciple is stronger than the master body, some work faster and more efficient, the so-called pneumatic sheng, young young means more likely, the progress of space bigger, vision more novel, more in the long run.
When people have faith, a nation has hope and a country has strength. The youth is the strongest and most hopeful.
I wish Chinese youth to get rid of the cold air, just go up, do not have to listen to the words of self-abandonment. Those who can work, those who can speak. There is a heat, send a light. Then, if there is no fire, I am the only light. If there is fire and the sun, we naturally disappear with complete satisfaction. Not only are there no complaints, but we also have to freely praise the fire or the sun. Because it reflects on people, including me. — — — — — – lu xun