Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between MVP MVC and MVVM

Folks I have gone through many links/blogs. I see most of them not able to clearly communicate in layman language and as well technical difference between MVP, MVVM and MVC. I know what every character stands for and also worked on MVP. But dont really understand if someone asks me the same question. Why cant I use controller in MvP instead of Presenter ? And why View Model in MVVM instead of presenter and how does it differs ? I can in a single sentense say"MVC is optimized for ASP.NET and also has templates in VS, MVP is optimized for winforms and MVVM for SL/WPF as it supports inbuilt binding features etc". But I feel that its not what I have to understand, but in detail and deep. Could some one throw light on this with detailed explanation and usage and actual reason to choose one. Thank you all...

like image 619
Jasmine Avatar asked Jul 09 '12 18:07

Jasmine


People also ask

What is the difference between MVC and MVVM?

Key Differences between MVC and MVVMIn MVC, controller is the entry point to the Application, while in MVVM, the view is the entry point to the Application. MVC Model component can be tested separately from the user, while MVVM is easy for separate unit testing, and code is event-driven.

Why MVP is better than MVVM?

But the major difference is communication back to the view. Whereas in MVVM there is usually a separate publisher for each piece of data, in MVI a single object defining the entire state of the view is published.

What is the difference between MVVM and MVP Swift?

In MVP a Presenter has reference/access to the View, i.e. you can directly bind to Click events or call a control's method from the Presenter. In MVVM this isn't allowed, as this breaks it.


1 Answers

I can't give you a complete answer, however I did struggle to learn some of these patterns and might be able to give you an idea about some of the main differences.

I learned MVVM first, and then MVC. I am aware of MVP and how it works in theory, however I have never actually built an application with it.

The biggest difference between the design patterns seems to be who controls the application flow and logic.

In MVVM, your code classes (ViewModels) are your application, while your Views are just a pretty user-friendly interface that sits on top of the application code and allows users to interact with it. This means the ViewModels have a huge job, because they are your application, and are responsible for everything from application flow to business logic.

With MVC, your Views are your application, while your Controller handles application flow. Application logic is typically found in ViewModels, which are considered part of the M in MVC (sidenote: the M in MVC cannot be considered the same as the M in MVVM because MVC's M layer contains more functionality than MVVM's M layer). A user is given a screen (View), they interact with it then submit something to the Controller, and the Controller decides who does what with the data and returns a new View to the user.

I have not used MVP, however my understanding of it was very similar to MVC, but optimized for a desktop application instead of a client/server application. The Views are the actual application, while the Presenter handles application events and business logic.

like image 105
Rachel Avatar answered Oct 02 '22 00:10

Rachel