MVC MVVM MVP

Source: Internet
Author: User

MVC, as the name implies, is the separation of model, view, and controller, so that each other's responsibilities (responsibility) can be clearly separated, so that whether you change M, V or C, you can ensure that the other two layers do not have to make any changes, At the same time, such a hierarchy can also enhance the testability of the program (testability), the view and model are basically related, but they do not have a direct dependency, but by the controller to determine the model generated data, and then throw to the view to render, that is to say ,Controller is the Coordinator (Coordinator) between model and view, and view and model cannot communicate directly to ensure separation of responsibilities. A controller can be a small class of binding model and view, or it can be a logical system that contains workflow, Enterprise services, or proxy services as an external system. , MVC components are separable components or separate systems (of course, some mechanisms are designed to communicate with each other).

MVVM,MVVM architecture is M, v separate, but in the middle is a VM (ViewModel) to Thread, the ViewModel is more like a view of the agent, it is responsible for direct model communication, and view can be through a number of mechanisms (ex: Events, two-way databindings, ...) To communicate with ViewModel to obtain information or to throw information into model for access, ViewModel can also act as an agent for external systems such as Web service or rest service or enterprise Services and so on, but it differs from MVC in that ViewModel and view have a higher degree of bonding, because view has to be viewmodel to get the model, and ViewModel has to deal with the notification message from view. So while the responsibilities are clear, they are not as extensible as MVC and can be used for the entire system component. If MVVM were to compare with MVP, MVVM would be a little more flexible than MVP.

MVP is also a well-defined, model-and-view architecture, but this p (Presenter) and ViewModel are similar, but like the meaning of the word Presenter (host), the work of all master view representations, is done by presenter, and the view itself is only the stage presenter to use , so the view is in principle dependent on presenter, but in order to achieve the focus separation (Soc principle), So a interface (Ex:iview) is added between the view and the presenter, and the view is injected into the presenter as an IOC, and presenter is manipulated using the method defined by the interface. The view is presented through the interface-defined method. But also because the interface is limited, so presenter can only follow the interface definition of the action to respond and processing, and can not do more extension function, unless you change the view interface.

  

From the discussion of the above architectures, we can get the following results:

    1. The MVC architecture is suitable for large systems that can be layered and cut into different machines or services at the entity level, provided they have the appropriate communication protocols.
    2. The MVVM architecture is suitable for user interface designs that are code-independent (code ignorance), such as XAML, that can enjoy viewmodel communication as long as the specific instruction in the view is connected to the ViewModel, and ViewModel Just do some special interface implementation, you can smooth and view communication.
    3. The MVP architecture is suitable for applications that centralize code-defined view actions, and view only needs to implement a specific interface and does not require too much work, but presenter may be constrained by the action of the View interface and not be able to further control the view.

Finally, I would like to mention that MVC is more tolerant than MVVM and MVP, in the MVC v layer, can further include the implementation of MVVM or MVP, and the C layer can also use MVP (V is the output of data) to further cut the flow and output of data, M layer can be similar to the MVVM architecture, when V (component) When there is data, the VM can automatically detect and update the model (database). Of course, what kind of architecture to design, look at the system environment and requirements at the time to decide, rather than just want to use the same architecture to do all the system.

MVC MVVM MVP

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.