MVC, MVP, MVVM

Source: Internet
Author: User

The concept of MVC is that we should all be strangers. In short, MVC is model, view, and controller, respectively. Model is responsible for data and access to data, view is responsible for presentation, Controller is responsible for business logic. In this way, each function module is good to separate and test.

After touching the front end, there are a lot of other terminology. Includes MVP and MVVM. This is the MVP and MVVM for today.

In fact, their difference is very simple. First, a picture, and then some text to explain.

The traditional MVC pattern is defined first. In this mode, the user interacts with the view and then the view passes the user's actions to the Controller,controller to update the model according to the business logic. The view takes the observer's way to judge the change of the model and then updates the view itself.

Advantages: Different functions are layered, which facilitates the modularization of functions.

Disadvantage: Because the controller relies on view, it is not easy to test.

And then the MVP. In this mode, C changes to P, which changes from controller to presenter. At this point, the view is not updated by listening to the model, but instead presenter the view by changing the model and then using the interface provided by the view.

Advantage: The function is concentrated in presenter, so it is easy to test.

Disadvantage: May lead to presenter too large.

And finally, MVVM. In this mode, C becomes viewmodel. At this point, the call relationship is almost the same as the MVP, and the difference is that there is a special binder in ViewModel that is responsible for synchronizing the data. This ensures that the view and model are consistent and reduces the amount of ViewModel code.

Advantages: Reduce controller size, easy maintenance.

Cons: Too much to introduce, not suitable for small applications.

MVC, MVP, MVVM

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.