What is difference between MVC, MVP & MVVM design pattern in terms of coding c#

后端 未结 5 1103
眼角桃花
眼角桃花 2020-11-30 15:52

If we search Google using the phrase \"What is difference between MVC, MVP & MVVM design pattern\" then we may get few URL\'s which discuss the difference between MVC MV

相关标签:
5条回答
  • 2020-11-30 16:26

    The image below is from the article written by Erwin van der Valk:

    image explaining MVC, MVP and MVVM - by Erwin Vandervalk

    The article explains the differences and gives some code examples in C#

    0 讨论(0)
  • 2020-11-30 16:30

    MVC, MVP, MVVM

    MVC (old one)

    MVP (more modular because of its low-coupling. Presenter is a mediator between the View and Model)

    MVVM (You already have two-way binding between VM and UI component, so it is more automated than MVP)

    Another image:

    0 讨论(0)
  • 2020-11-30 16:37

    Great Explanation from the link : http://geekswithblogs.net/dlussier/archive/2009/11/21/136454.aspx

    Let's First look at MVC

    The input is directed at the Controller first, not the view. That input might be coming from a user interacting with a page, but it could also be from simply entering a specific url into a browser. In either case, its a Controller that is interfaced with to kick off some functionality.

    There is a many-to-one relationship between the Controller and the View. That’s because a single controller may select different views to be rendered based on the operation being executed.

    There is one way arrow from Controller to View. This is because the View doesn’t have any knowledge of or reference to the controller.

    The Controller does pass back the Model, so there is knowledge between the View and the expected Model being passed into it, but not the Controller serving it up.

    MVP – Model View Presenter

    Now let’s look at the MVP pattern. It looks very similar to MVC, except for some key distinctions:

    The input begins with the View, not the Presenter.

    There is a one-to-one mapping between the View and the associated Presenter.

    The View holds a reference to the Presenter. The Presenter is also reacting to events being triggered from the View, so its aware of the View its associated with.

    The Presenter updates the View based on the requested actions it performs on the Model, but the View is not Model aware.

    MVVM – Model View View Model

    So with the MVC and MVP patterns in front of us, let’s look at the MVVM pattern and see what differences it holds:

    The input begins with the View, not the View Model.

    While the View holds a reference to the View Model, the View Model has no information about the View. This is why its possible to have a one-to-many mapping between various Views and one View Model…even across technologies. For example, a WPF View and a Silverlight View could share the same View Model.

    0 讨论(0)
  • 2020-11-30 16:48

    Some basic differences can be written in short:

    MVC:

    Traditional MVC is where there is a

    1. Model: Acts as the model for data
    2. View : Deals with the view to the user which can be the UI
    3. Controller: Controls the interaction between Model and View, where view calls the controller to update model. View can call multiple controllers if needed.

    MVP:

    Similar to traditional MVC but Controller is replaced by Presenter. But the Presenter, unlike Controller is responsible for changing the view as well. The view usually does not call the presenter.

    MVVM

    The difference here is the presence of View Model. It is kind of an implementation of Observer Design Pattern, where changes in the model are represented in the view as well, by the VM. Eg: If a slider is changed, not only the model is updated but the data which may be a text, that is displayed in the view is updated as well. So there is a two-way data binding.

    0 讨论(0)
  • 2020-11-30 16:51

    MVP:

    Advantages:

    Presenter will be present in between Model and view.Presenter will fetch data from Model and will do manipulations for data as view wants and give it to view and view is responsible only for rendering.

    Disadvantages:

    1)We can't use presenter for multiple modules because data is being modified in presenter as desired by one view class.

    3)Breaking Clean architecture because data flow should be only outwards but here data is coming back from presenter to View.

    MVC:

    Advanatages:

    Here we have Controller in between view and model.Here data request will be done from controller to view but data will be sent back to view in form of interface but not with controller.So,here controller won't get bloated up because of many transactions.

    Disadvantagaes:

    Data Manipulation should be done by View as it wants and this will be extra work on UI thread which may effect UI rendering if data processing is more.

    MVVM:

    After announcing Architectural components,we got access to ViewModel which provided us biggest advantage i.e it's lifecycle aware.So,it won't notify data if view is not available.It is a clean architecture because flow is only in forward mode and data will be notified automatically by LiveData. So,it is Android's recommended architecture.

    Even MVVM has a disadvantage. Since it is a lifecycle aware some concepts like alarm or reminder should come outside app.So,in this scenario we can't use MVVM.

    0 讨论(0)
提交回复
热议问题