15

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...

Jasmine
  • 5,186
  • 16
  • 62
  • 114
  • 3
    There's lots of help here: https://www.google.com/#q=difference+between+MVP+MVC+and+MVVM. What can we say that isn't already adequately covered in those blogs? – Robert Harvey Jul 09 '12 at 18:12
  • 6
    @RobertHarvey: Most blogs actually confuses and people keep repeating the same copy pasting. I dont see that in a way that its precise and understandable by all. I am also sure, many are like me who still cant clearly explain the differences if asked. I would prefer a lay man sentences explaining difference of 3 and also as I asked, what if I replace Controller with Present and presenter with view model. I want answers to these types of questions. Also technical difference. (Because all are into single goal) – Jasmine Jul 09 '12 at 18:15
  • SO is for specific programming questions. – paparazzo Jul 09 '12 at 18:20
  • 1
    @Divine Frankly, it would be a lot of work to explain in one answer and there are some conflicting opinions, maybe you can research on your own and come up with a more specific question. – Garrett Hall Jul 09 '12 at 18:49
  • @GarrettHall: Soothing answer, sure, I understand it Garrett, although I am a newbie :( .... ANyway I will try to explore myself more :) Thanks again, cheers – Jasmine Jul 09 '12 at 18:53
  • 2
    @Divine like many parts of programming even after reading it can be hard to understand until you've actually programmed in it. Not many of programmers have worked with MVC, MVVM, and MVP and even if they have it was probably with different languages/frameworks, so finding good comparisons is quite difficult, although I would like to know myself. – Garrett Hall Jul 09 '12 at 19:42
  • @GarrettHall: Very true. But this question is a quite common question in interviews (Whether the interviewer know the answer or not, but been screwing up many a times :( ).... Well anyways :) Thanks again for your reply. – Jasmine Jul 10 '12 at 03:42

2 Answers2

12

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.

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • Thank you so much Rachel for sharing your knowledge and experience. It really helps me a lot for understanding. I appreciate it. I will go through more, thanks again Madam :) Cheers – Jasmine Jul 09 '12 at 19:02
  • FYI, MVP comes in two flavors: passive view and supervising controller. Passive view is quite different than MVC. From my understanding MVP is also suitable for web (GWT). – Garrett Hall Jul 09 '12 at 19:40
  • 2
    @GarrettHall Thanks, I really don't know much about MVP at all. I am guessing "passive view" means it passively waits for event messages and responds to them like MVC's Controller does, while "supervising controller" means it takes charge of the entire application flow more like MVVM's ViewModel does? Kind of like a passive boss who sits back and only intervenes in your work if there's a problem, or a controlling boss that likes to micro-manage your work? :) – Rachel Jul 09 '12 at 20:11
  • @Rachel Haha, that is the perfect analogy. – Garrett Hall Jul 10 '12 at 13:37
  • 2
    I find this answer very simplistic and arguably inaccurate. In MVVM, VM do not always dictacte application flow. In WPF for example, application flow can be completely done in the V with zero-code-behind. The "application" in this answer is implying business logic and if so you do not put business logic in VM in MVVM nor M in MVC. The author has completely missed the whole point of V in MVVM where you generally limit the amount of code-behind so they are hardly "pretty user-friendly interface". VM do not have a huge job. As mentioned you limit the amount of business logic placed there. –  Dec 05 '13 at 23:41
1

In MVC you have Model View Controller linked as a triangle In MVP you have Model View Presenter linked lineary Basically MVC and MVP are very much similar, however it's simplier to work with MVC, even because you already have built in MS plugin to create and separate your M-V-C providing its advantages With MVP your app would look like like a general ASP.NET app , means: no Razor, no .cshtml for the views, etc. and you have to deal with the structure on your own. MVVM is generally used in Silverlight/WPF and for those techs it's the best choice. The idea of MVVM and MVC are pretty much similar. You can also apply MVVM on a client side of your web app if you use knockout.