<p>When looking beyond the <a href="https://en.wikipedia.org/wiki/Rapid_application_development" rel="noreferrer">RAD</a> (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="noreferrer">Model-View-Controller</a>, <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter" rel="noreferrer">Model-View-Presenter</a> and <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" rel="noreferrer">Model-View-ViewModel</a>. My question has three parts to it:</p>

<ol>
<li>What issues do these patterns address?</li>
<li>How are they similar?</li>
<li>How are they different?</li>
</ol>

[{'answer_id': 2067, 'author': 'Matt Mitchell', 'author_id': 364, 'author_profile': 'https://Stackoverflow.com/users/364', 'pm_score': 4, 'selected': False, 'text': '<p>Both of these frameworks aim to seperate concerns - for instance, interaction with a data source (model), application logic (or turning this data into useful information) (Controller/Presenter) and display code (View).  In some cases the model can also be used to turn a data source into a higher level abstraction as well.  A good example of this is the <a href="http://blog.wekeroad.com/mvc-storefront/" rel="noreferrer">MVC Storefront project</a>.</p>\n\n<p>There is a discussion <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/10/31/development-trivial-pursuit-the-difference-between-mvc-and-the-different-flavors-of-mvp.aspx" rel="noreferrer">here</a> regarding the differences between MVC vs MVP.</p>\n\n<p>The distinction made is that in an MVC application traditionally has the view and the controller interact with the model, but not with each other.</p>\n\n<p>MVP designs have the Presenter access the model and interact with the view.</p>\n\n<p>Having said that, ASP.NET MVC is by these definitions an MVP framework because the Controller accesses the Model to populate the View which is meant to have no logic (just  displays the variables provided by the Controller).</p>\n\n<p>To perhaps get an idea of the ASP.NET MVC distinction from MVP, check out <a href="http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx" rel="noreferrer">this MIX presentation</a> by Scott Hanselman.</p>\n'}, {'answer_id': 2068, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 9, 'selected': False, 'text': '<p>I blogged about this a while back, quoting on <a href="http://blogs.infragistics.com/blogs/todd_snyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx" rel="noreferrer">Todd Snyder\'s excellent post on the difference between the two</a>:</p>\n\n<blockquote>\n  <p>Here are the key differences between\n  the patterns:</p>\n  \n  <p><strong>MVP Pattern</strong></p>\n  \n  <ul>\n  <li>View is more loosely coupled to the model. The presenter is\n  responsible for binding the model to\n  the view.</li>\n  <li>Easier to unit test because interaction with the view is through\n  an interface</li>\n  <li>Usually view to presenter map one to one. Complex views may have\n  multi presenters.</li>\n  </ul>\n  \n  <p><strong>MVC Pattern</strong></p>\n  \n  <ul>\n  <li>Controller are based on behaviors and can be shared across\n  views</li>\n  <li>Can be responsible for determining which view to display</li>\n  </ul>\n</blockquote>\n\n<p>It is the best explanation on the web I could find.</p>\n'}, {'answer_id': 2069, 'author': 'Brett Veenstra', 'author_id': 307, 'author_profile': 'https://Stackoverflow.com/users/307', 'pm_score': 5, 'selected': False, 'text': '<ul>\n<li>MVP = Model-View-Presenter</li>\n<li><p>MVC = Model-View-Controller</p>\n\n<ol>\n<li>Both presentation patterns.  They separate the dependencies between a Model (think Domain objects), your screen/web page (the View), and how your UI is supposed to behave (Presenter/Controller)</li>\n<li>They are fairly similar in concept, folks initialize the Presenter/Controller differently depending on taste.</li>\n<li>A great article on the differences is <a href="http://www.infragistics.com/community/blogs/todd_snyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx" rel="noreferrer">here</a>.  Most notable is that MVC pattern has the Model updating the View.</li>\n</ol></li>\n</ul>\n'}, {'answer_id': 4087, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 7, 'selected': False, 'text': '<h3>MVP: the view is in charge.</h3>\n<p>The view, in most cases, creates its presenter. The presenter will interact with the model and manipulate the view through an interface. The view will sometimes interact with the presenter, usually through some interface.  This comes down to implementation; do you want the view to call methods on the presenter or do you want the view to have events the presenter listens to? It boils down to this: The view knows about the presenter. The view delegates to the presenter.</p>\n<h3>MVC: the controller is in charge.</h3>\n<p>The controller is created or accessed based on some event/request. The controller then creates the appropriate view and interacts with the model to further configure the view. It boils down to: the controller creates and manages the view; the view is slave to the controller. The view does not know about the controller.</p>\n'}, {'answer_id': 5712, 'author': 'Jonas Follesø', 'author_id': 1199387, 'author_profile': 'https://Stackoverflow.com/users/1199387', 'pm_score': 5, 'selected': False, 'text': '<p>Also worth remembering is that there are different types of MVPs as well. Fowler has broken the pattern into two - Passive View and Supervising Controller.</p>\n\n<p>When using Passive View, your View typically implement a fine-grained interface with properties mapping more or less directly to the underlaying UI widget. For instance, you might have a ICustomerView with properties like Name and Address.</p>\n\n<p>Your implementation might look something like this:</p>\n\n<pre><code>public class CustomerView : ICustomerView\n{\n    public string Name\n    { \n        get { return txtName.Text; }\n        set { txtName.Text = value; }\n    }\n}\n</code></pre>\n\n<p>Your Presenter class will talk to the model and "map" it to the view. This approach is called the "Passive View". The benefit is that the view is easy to test, and it is easier to move between UI platforms (Web, Windows/XAML, etc.). The disadvantage is that you can\'t leverage things like databinding (which is <em>really</em> powerful in frameworks like <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" rel="noreferrer">WPF</a> and <a href="http://en.wikipedia.org/wiki/Microsoft_Silverlight" rel="noreferrer">Silverlight</a>).</p>\n\n<p>The second flavor of MVP is the Supervising Controller. In that case your View might have a property called Customer, which then again is databound to the UI widgets. You don\'t have to think about synchronizing and micro-manage the view, and the Supervising Controller can step in and help when needed, for instance with compled interaction logic.</p>\n\n<p>The third "flavor" of MVP (or someone would perhaps call it a separate pattern) is the Presentation Model (or sometimes referred to Model-View-ViewModel). Compared to the MVP you "merge" the M and the P into one class. You have your customer object which your UI widgets is data bound to, but you also have additional UI-spesific fields like "IsButtonEnabled", or "IsReadOnly", etc.</p>\n\n<p>I think the best resource I\'ve found to UI architecture is the series of blog posts done by Jeremy Miller over at <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx" rel="noreferrer">The Build Your Own CAB Series Table of Contents</a>. He covered all the flavors of MVP and showed C# code to implement them.</p>\n\n<p>I have also blogged about the Model-View-ViewModel pattern in the context of Silverlight over at <em><a href="http://jonas.follesoe.no/2008/07/19/youcard-re-visited-implementing-the-viewmodel-pattern" rel="noreferrer">YouCard Re-visited: Implementing the ViewModel pattern</a></em>.</p>\n'}, {'answer_id': 26933, 'author': 'Quibblesome', 'author_id': 1143, 'author_profile': 'https://Stackoverflow.com/users/1143', 'pm_score': 8, 'selected': False, 'text': '<p>MVP is <em>not</em> necessarily a scenario where the View is in charge (see Taligent\'s MVP for example).<br>\nI find it unfortunate that people are still preaching this as a pattern (View in charge) as opposed to an anti-pattern as it contradicts "It\'s just a view" (Pragmatic Programmer). "It\'s just a view" states that the final view shown to the user is a secondary concern of the application. Microsoft\'s MVP pattern renders re-use of Views much more difficult and <em>conveniently</em> excuses Microsoft\'s designer from encouraging bad practice.</p>\n\n<p>To be perfectly frank, I think the underlying concerns of MVC hold true for any MVP implementation and the differences are almost entirely semantic. As long as you are following separation of concerns between the view (that displays the data), the controller (that initialises and controls user interaction) and the model (the underlying data and/or services)) then you are achieving the benefits of MVC. If you are achieving the benefits then who really cares whether your pattern is MVC, MVP or Supervising Controller? The only <em>real</em> pattern remains as MVC, the rest are just differing flavours of it.</p>\n\n<p>Consider <a href="https://lostechies.com/derekgreer/2007/08/25/interactive-application-architecture/" rel="noreferrer">this</a> highly exciting article that comprehensively lists a number of these differing implementations. \nYou may note that they\'re all basically doing the same thing but slightly differently.</p>\n\n<p>I personally think MVP has only been recently re-introduced as a catchy term to either reduce arguments between semantic bigots who argue whether something is truly MVC or not or to justify Microsofts Rapid Application Development tools. Neither of these reasons in my books justify its existence as a separate design pattern.</p>\n'}, {'answer_id': 101561, 'author': 'Glenn Block', 'author_id': 18419, 'author_profile': 'https://Stackoverflow.com/users/18419', 'pm_score': 12, 'selected': True, 'text': '<h2>Model-View-Presenter</h2>\n<p>In <strong>MVP</strong>, the Presenter contains the UI business logic for the View. All invocations from the View delegate directly to the Presenter. The Presenter is also decoupled directly from the View and talks to it through an interface. This is to allow mocking of the View in a unit test. One common attribute of MVP is that there has to be a lot of two-way dispatching. For example, when someone clicks the &quot;Save&quot; button, the event handler delegates to the Presenter\'s &quot;OnSave&quot; method. Once the save is completed, the Presenter will then call back the View through its interface so that the View can display that the save has completed.</p>\n<p>MVP tends to be a very natural pattern for achieving separated presentation in WebForms. The reason is that the View is always created first by the ASP.NET runtime. You can <a href="https://web.archive.org/web/20071211153445/http://www.codeplex.com/websf/Wiki/View.aspx?title=MVPDocumentation" rel="noreferrer">find out more about both variants</a>.</p>\n<h3>Two primary variations</h3>\n<p><strong>Passive View:</strong> The View is as dumb as possible and contains almost zero logic. A Presenter is a middle man that talks to the View and the Model. The View and Model are completely shielded from one another. The Model may raise events, but the Presenter subscribes to them for updating the View. In Passive View there is no direct data binding, instead, the View exposes setter properties that the Presenter uses to set the data. All state is managed in the Presenter and not the View.</p>\n<ul>\n<li>Pro: maximum testability surface; clean separation of the View and Model</li>\n<li>Con: more work (for example all the setter properties) as you are doing all the data binding yourself.</li>\n</ul>\n<p><strong>Supervising Controller:</strong> The Presenter handles user gestures. The View binds to the Model directly through data binding. In this case, it\'s the Presenter\'s job to pass off the Model to the View so that it can bind to it. The Presenter will also contain logic for gestures like pressing a button, navigation, etc.</p>\n<ul>\n<li>Pro: by leveraging data binding the amount of code is reduced.</li>\n<li>Con: there\'s a less testable surface (because of data binding), and there\'s less encapsulation in the View since it talks directly to the Model.</li>\n</ul>\n<h2>Model-View-Controller</h2>\n<p>In the <strong>MVC</strong>, the Controller is responsible for determining which View to display in response to any action including when the application loads. This differs from MVP where actions route through the View to the Presenter. In MVC, every action in the View correlates with a call to a Controller along with an action. In the web, each action involves a call to a URL on the other side of which there is a Controller who responds. Once that Controller has completed its processing, it will return the correct View. The sequence continues in that manner throughout the life of the application:</p>\n<pre>\n    Action in the View\n        -> Call to Controller\n        -> Controller Logic\n        -> Controller returns the View.\n</pre>\n<p>One other big difference about MVC is that the View does not directly bind to the Model. The view simply renders and is completely stateless. In implementations of MVC, the View usually will not have any logic in the code behind. This is contrary to MVP where it is absolutely necessary because, if the View does not delegate to the Presenter, it will never get called.</p>\n<h2>Presentation Model</h2>\n<p>One other pattern to look at is the <strong>Presentation Model</strong> pattern. In this pattern, there is no Presenter. Instead, the View binds directly to a Presentation Model. The Presentation Model is a Model crafted specifically for the View. This means this Model can expose properties that one would never put on a domain model as it would be a violation of separation-of-concerns. In this case, the Presentation Model binds to the domain model and may subscribe to events coming from that Model. The View then subscribes to events coming from the Presentation Model and updates itself accordingly. The Presentation Model can expose commands which the view uses for invoking actions. The advantage of this approach is that you can essentially remove the code-behind altogether as the PM completely encapsulates all of the behavior for the view. This pattern is a very strong candidate for use in WPF applications and is also called <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="noreferrer">Model-View-ViewModel</a>.</p>\n<p>There is a <a href="http://msdn.microsoft.com/en-us/library/ff921080.aspx" rel="noreferrer">MSDN article about the Presentation Model</a> and a section in the <a href="http://msdn.microsoft.com/en-us/library/cc707819.aspx" rel="noreferrer">Composite Application Guidance for WPF</a> (former Prism) about <a href="http://msdn.microsoft.com/en-us/library/cc707862.aspx" rel="noreferrer">Separated Presentation Patterns</a></p>\n'}, {'answer_id': 110908, 'author': 'Nikola Malovic', 'author_id': 19934, 'author_profile': 'https://Stackoverflow.com/users/19934', 'pm_score': 4, 'selected': False, 'text': '<p>Both are patterns trying to separate presentation and business logic, decoupling business logic from UI aspects</p>\n\n<p>Architecturally, MVP is Page Controller based approach where MVC is Front Controller based approach. \nThat means that in MVP standard web form page life cycle is just enhanced by extracting the business logic from code behind. In other words, page is the one servicing http request. In other words, MVP IMHO is web form evolutionary type of enhancement.\nMVC on other hand changes completely the game because the request gets intercepted by controller class before page is loaded, the business logic is executed there and then at the end result of controller processing the data just dumped to the page ("view")\nIn that sense, MVC looks (at least to me) a lot to Supervising Controller flavor of MVP enhanced with routing engine </p>\n\n<p>Both of them enable TDD and have downsides and upsides. </p>\n\n<p>Decision on how to choose one of them IMHO should be based on how much time one invested in ASP NET web form type of web development. \nIf one would consider himself good in web forms, I would suggest MVP. \nIf one would feel not so comfortable in things such as page life cycle etc MVC could be a way to go here.</p>\n\n<p>Here\'s yet another blog post link giving a little bit more details on this topic </p>\n\n<p><a href="http://blog.vuscode.com/malovicn/archive/2007/12/18/model-view-presenter-mvp-vs-model-view-controller-mvc.aspx" rel="noreferrer">http://blog.vuscode.com/malovicn/archive/2007/12/18/model-view-presenter-mvp-vs-model-view-controller-mvc.aspx</a></p>\n'}, {'answer_id': 406470, 'author': 'Pedro Santos', 'author_id': 50850, 'author_profile': 'https://Stackoverflow.com/users/50850', 'pm_score': 3, 'selected': False, 'text': '<p>I have used both MVP and MVC and although we as developers tend to focus on the technical differences of both patterns the point for MVP in IMHO is much more related to ease of adoption than anything else. </p>\n\n<p>If I’m working in a team that already as a good background on web forms development style it’s far easier to introduce MVP than MVC. I would say that MVP in this scenario is a quick win. </p>\n\n<p>My experience tells me that moving  a team from web forms to MVP and then from MVP to MVC is relatively easy; moving from web forms to MVC is more difficult.</p>\n\n<p>I leave here a link to a series of articles a friend of mine has published about MVP and MVC.</p>\n\n<p><a href="http://www.qsoft.be/post/Building-the-MVP-StoreFront-Gutthrie-style.aspx" rel="noreferrer">http://www.qsoft.be/post/Building-the-MVP-StoreFront-Gutthrie-style.aspx</a></p>\n'}, {'answer_id': 14985493, 'author': 'Hibou57', 'author_id': 279335, 'author_profile': 'https://Stackoverflow.com/users/279335', 'pm_score': 3, 'selected': False, 'text': '<p>My humble short view: MVP is for large scales, and MVC for tiny scales. With MVC, I sometime feel the V and the C may be seen a two sides of a single indivisible component rather directly bound to M, and one inevitably falls to this when going down‑to shorter scales, like UI controls and base widgets. At this level of granularity, MVP makes little sense. When one on the contrary go to larger scales, proper interface becomes more important, the same with unambiguous assignment of responsibilities, and here comes MVP.</p>\n\n<p>On the other hand, this scale rule of a thumb, may weight very little when the platform characteristics favours some kind of relations between the components, like with the web, where it seems to be easier to implement MVC, more than MVP.</p>\n'}, {'answer_id': 16993091, 'author': 'James Roeiter', 'author_id': 1135393, 'author_profile': 'https://Stackoverflow.com/users/1135393', 'pm_score': 3, 'selected': False, 'text': "<p>In MVP the view draws data from the presenter which draws and prepares/normalizes data from the model while in MVC the controller draws data from the model and set, by push in the view.</p>\n\n<p>In MVP you can have a single view working with multiple types of presenters and a single presenter working with different multiple views.</p>\n\n<p>MVP usually uses some sort of a binding framework, such as Microsoft WPF binding framework or various binding frameworks for HTML5 and Java. </p>\n\n<p>In those frameworks, the UI/HTML5/XAML, is aware of what property of the presenter each UI element displays, so when you bind a view to a presenter, the view looks for the properties and knows how to draw data from them and how to set them when a value is changed in the UI by the user.</p>\n\n<p>So, if for example, the model is a car, then the presenter is some sort of a car presenter, exposes the car properties (year, maker, seats, etc.) to the view. The view knows that the text field called 'car maker' needs to display the presenter Maker property. </p>\n\n<p>You can then bind to the view many different types of presenter, all must have Maker property - it can be of a plane, train or what ever , the view doesn't care. The view draws data from the presenter - no matter which - as long as it implements an agreed interface.</p>\n\n<p>This binding framework, if you strip it down, it's actually the controller :-) </p>\n\n<p>And so, you can look on MVP as an evolution of MVC. </p>\n\n<p>MVC is great, but the problem is that usually its controller per view. Controller A knows how to set fields of View A. If now, you want View A to display data of model B, you need Controller A to know model B, or you need Controller A to receive an object with an interface - which is like MVP only without the bindings, or you need to rewrite the UI set code in Controller B.</p>\n\n<p>Conclusion - MVP and MVC are both decouple of UI patterns, but MVP usually uses a bindings framework which is MVC underneath. THUS MVP is at a higher architectural level than MVC and a wrapper pattern above of MVC.</p>\n"}, {'answer_id': 17507611, 'author': 'Phyxx', 'author_id': 157605, 'author_profile': 'https://Stackoverflow.com/users/157605', 'pm_score': 9, 'selected': False, 'text': '<p>This is an oversimplification of the many variants of these design patterns, but this is how I like to think about the differences between the two.</p>\n\n<p><strong>MVC</strong></p>\n\n<p><img src="https://i.stack.imgur.com/X3CAF.png" alt="MVC"></p>\n\n<p><strong>MVP</strong></p>\n\n<p><img src="https://i.stack.imgur.com/Pa0iB.png" alt="enter image description here"></p>\n'}, {'answer_id': 25816573, 'author': 'Ashraf Bashir', 'author_id': 202940, 'author_profile': 'https://Stackoverflow.com/users/202940', 'pm_score': 8, 'selected': False, 'text': '<p>Here are illustrations which represent communication flow<br/></p>\n\n<p><img src="https://i.stack.imgur.com/t2kzD.png" alt="enter image description here"> <br /><br />\n<img src="https://i.stack.imgur.com/adMfR.png" alt="enter image description here"></p>\n'}, {'answer_id': 32470069, 'author': 'onmyway133', 'author_id': 1418457, 'author_profile': 'https://Stackoverflow.com/users/1418457', 'pm_score': 3, 'selected': False, 'text': '<p>There are many versions of MVC, this answer is about the original MVC in Smalltalk. In brief, it is\n<a href="https://i.stack.imgur.com/aebJI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aebJI.png" alt="image of mvc vs mvp"></a></p>\n\n<p>This talk <a href="https://www.youtube.com/watch?v=i1-7S-RxfvQ" rel="noreferrer">droidcon NYC 2017 - Clean app design with Architecture Components</a> clarifies it</p>\n\n<p><a href="https://i.stack.imgur.com/wPqMA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wPqMA.png" alt="enter image description here"></a>\n<a href="https://i.stack.imgur.com/fTNfE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fTNfE.png" alt="enter image description here"></a></p>\n'}, {'answer_id': 34377336, 'author': 'AVI', 'author_id': 5222902, 'author_profile': 'https://Stackoverflow.com/users/5222902', 'pm_score': 6, 'selected': False, 'text': '<p><a href="https://i.stack.imgur.com/A7cSy.jpg"><img src="https://i.stack.imgur.com/A7cSy.jpg" alt="enter image description here"></a></p>\n\n<p><strong>MVC (Model View Controller)</strong></p>\n\n<p>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.\nThere 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.\nNote the one way arrow from Controller to View. This is because the View doesn’t have any knowledge of or reference to the controller.\nThe 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.</p>\n\n<p><strong>MVP (Model View Presenter)</strong></p>\n\n<p>The input begins with the View, not the Presenter.\nThere is a one-to-one mapping between the View and the associated Presenter.\nThe 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.\nThe Presenter updates the View based on the requested actions it performs on the Model, but the View is not Model aware.</p>\n\n<p>For more <a href="http://geekswithblogs.net/dlussier/archive/2009/11/21/136454.aspx">Reference</a></p>\n'}, {'answer_id': 34735827, 'author': 'marvelTracker', 'author_id': 755120, 'author_profile': 'https://Stackoverflow.com/users/755120', 'pm_score': 0, 'selected': False, 'text': '<p><strong>MVP</strong></p>\n\n<p>MVP stands for Model - View- Presenter. This came to a picture in early 2007 where Microsoft introduced Smart Client windows applications. </p>\n\n<p>A presenter is acting as a supervisory role in MVP which binding View events and business logic from models.</p>\n\n<p>View event binding will be implemented in the Presenter from a view interface. </p>\n\n<p>The view is the initiator for user inputs and then delegates the events to the Presenter and the presenter handles event bindings and gets data from models.</p>\n\n<p><strong>Pros:</strong>\n    The view is having only  UI not any logics\n    High level of testability </p>\n\n<p><strong>Cons:</strong>\n    Bit complex and more work when implementing event bindings</p>\n\n<p><strong>MVC</strong></p>\n\n<p>MVC stands for Model-View-Controller. Controller is responsible for creating models and rendering views with binding models. </p>\n\n<p>Controller is the initiator and it decides which view to render. </p>\n\n<p><strong>Pros:</strong>\n  Emphasis on Single Responsibility Principle\n  High level of testability </p>\n\n<p><strong>Cons:</strong>\n  Sometimes too much workload for Controllers, if try to render multiple views in same controller. </p>\n'}, {'answer_id': 47335855, 'author': 'Clive Jefferies', 'author_id': 447549, 'author_profile': 'https://Stackoverflow.com/users/447549', 'pm_score': 3, 'selected': False, 'text': '<p>The simplest answer is how the view interacts with the model. In MVP the view is updated by the presenter, which acts as as intermediary between the view and the model. The presenter takes the input from the view, which retrieves the data from the model and then performs any business logic required and then updates the view. In MVC the model updates the view directly rather than going back through the controller.</p>\n'}, {'answer_id': 47550217, 'author': 'Rahul', 'author_id': 6138892, 'author_profile': 'https://Stackoverflow.com/users/6138892', 'pm_score': 5, 'selected': False, 'text': '<p><strong>Model-View-Controller</strong></p>\n\n<p><strong>MVC</strong> is a pattern for the architecture of a software application. It separate the application logic into three separate parts, promoting modularity and ease of collaboration and reuse. It also makes applications more flexible and welcoming to iterations.It separates an application into the following components:</p>\n\n<ul>\n<li><strong>Models</strong> for handling data and business logic</li>\n<li><strong>Controllers</strong> for handling the user interface and application</li>\n<li><strong>Views</strong> for handling graphical user interface objects and presentation</li>\n</ul>\n\n<p>To make this a little more clear, let\'s imagine a simple shopping list app. All we want is a list of the name, quantity and price of each item we need to buy this week. Below we\'ll describe how we could implement some of this functionality using MVC.</p>\n\n<p><a href="https://i.stack.imgur.com/xjBSZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xjBSZ.png" alt="enter image description here"></a></p>\n\n<p><strong>Model-View-Presenter</strong></p>\n\n<ul>\n<li>The <strong>model</strong> is the data that will be displayed in the view (user interface).</li>\n<li>The <strong>view</strong> is an interface that displays data (the model) and routes user commands (events) to the Presenter to act upon that data. The view usually has a reference to its Presenter.</li>\n<li>The <strong>Presenter</strong> is the “middle-man” (played by the controller in MVC) and has references to both, view and model. <strong>Please note that the word “Model”</strong> is misleading. It should rather be <strong>business logic that retrieves or manipulates a Model</strong>. For instance: If you have a database storing User in a database table and your View wants to display a list of users, then the Presenter would have a reference to your database business logic (like a DAO) from where the Presenter will query a list of Users.</li>\n</ul>\n\n<blockquote>\n  <p>If you want to see a sample with simple implementation please check\n  <a href="https://github.com/rahulabrol/Messanger" rel="noreferrer">this</a> GitHub post</p>\n</blockquote>\n\n<p>A concrete workflow of querying and displaying a list of users from a database could work like this:\n<a href="https://i.stack.imgur.com/QwKUW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QwKUW.png" alt="enter image description here"></a></p>\n\n<blockquote>\n  <p>What is the <strong>difference</strong> between <strong>MVC</strong> and <strong>MVP</strong> patterns?</p>\n</blockquote>\n\n<p><strong>MVC Pattern</strong></p>\n\n<ul>\n<li><p>Controller are based on behaviors and can be shared across views</p></li>\n<li><p>Can be responsible for determining which view to display (Front Controller Pattern)</p></li>\n</ul>\n\n<p><strong>MVP Pattern</strong></p>\n\n<ul>\n<li><p>View is more loosely coupled to the model. The presenter is responsible for binding the model to the view.</p></li>\n<li><p>Easier to unit test because interaction with the view is through an interface</p></li>\n<li><p>Usually view to presenter map one to one. Complex views may have multi presenters.</p></li>\n</ul>\n'}, {'answer_id': 48452128, 'author': 'stdout', 'author_id': 1388943, 'author_profile': 'https://Stackoverflow.com/users/1388943', 'pm_score': 3, 'selected': False, 'text': '<p>There is <a href="https://www.youtube.com/watch?v=WpkDN78P884&amp;feature=youtu.be&amp;t=29m1s" rel="nofollow noreferrer">this</a> nice video from Uncle Bob where he briefly explains <strong>MVC</strong> &amp; <strong>MVP</strong> at the end.</p>\n\n<p>IMO, MVP is an improved version of MVC where you basically separate the concern of what you\'re gonna show (the data) from how you\'re gonna show (the view). The presenter includes kinda the business logic of your UI, implicitly imposes what data should be presented and gives you a list of dumb view models. And when the time comes to show the data, you simply plug your view (probably includes the same id\'s) into your adapter and set the relevant view fields using those view models with a minimum amount of code being introduced (just using setters). Its main benefit is you can test your UI business logic against many/various views like showing items in a horizontal list or vertical list.  </p>\n\n<p>In MVC, we talk through interfaces (boundaries) to glue different layers. A controller is a plug-in to our architecture but it has no such a restriction to impose what to show. In that sense, MVP is kind of an MVC with a concept of views being pluggable to the controller over adapters. </p>\n\n<p>I hope this helps better.</p>\n'}, {'answer_id': 49694378, 'author': 'Ali Nem', 'author_id': 4514796, 'author_profile': 'https://Stackoverflow.com/users/4514796', 'pm_score': 6, 'selected': False, 'text': '<p>There are many answers to the question, but I felt there is a need for some really simple answer clearly comparing the two. Here\'s the discussion I made up when a user searches for a movie name in an MVP and MVC app:</p>\n<p>User: Click click …</p>\n<p><em>View</em>: Who’s that? [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p>User: I just clicked on the search button …</p>\n<p><em>View</em>: Ok, hold on a sec … . [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p>( <em>View</em> calling the <em>Presenter</em>|<em>Controller</em> … ) [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>View</em>: Hey <em>Presenter</em>|<em>Controller</em>, a User has just clicked on the search button, what shall I do? [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>Presenter</em>|<em>Controller</em>: Hey <em>View</em>, is there any search term on that page? [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>View</em>: Yes,… here it is … “piano” [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>Presenter</em>|<em>Controller</em>: Thanks <em>View</em>,… meanwhile I’m looking up the search term on the <em>Model</em>, please show him/her a progress bar [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p>( <em>Presenter</em>|<em>Controller</em> is calling the <em>Model</em> … ) [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>Presenter</em>|<em>Controller</em>: Hey <em>Model</em>, Do you have any match for this search term?: “piano” [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>Model</em>: Hey <em>Presenter</em>|<em>Controller</em>, let me check … [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p>( <em>Model</em> is making a query to the movie database … ) [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p>( After a while ... )</p>\n<p>-------------- This is where MVP and MVC start to diverge ---------------</p>\n<p><em>Model</em>: I found a list for you, <em>Presenter</em>, here it is in JSON “[{&quot;name&quot;:&quot;Piano Teacher&quot;,&quot;year&quot;:2001},{&quot;name&quot;:&quot;Piano&quot;,&quot;year&quot;:1993}]” [<strong>MVP</strong>]</p>\n<p><em>Model</em>: There is some result available, <em>Controller</em>. I have created a field variable in my instance and filled it with the result. It\'s name is &quot;searchResultsList&quot; [<strong>MVC</strong>]</p>\n<p>(<em>Presenter</em>|<em>Controller</em> thanks <em>Model</em> and gets back to the <em>View</em>) [<strong>MVP</strong>|<strong>MVC</strong>]</p>\n<p><em>Presenter</em>: Thanks for waiting <em>View</em>, I found a list of matching results for you and arranged them in a presentable format: [&quot;Piano Teacher 2001&quot;,&quot;Piano 1993&quot;]. Please show it to the user in a vertical list. Also please hide the progress bar now [<strong>MVP</strong>]</p>\n<p><em>Controller</em>: Thanks for waiting <em>View</em>, I have asked <em>Model</em> about your search query. It says it has found a list of matching results and stored them in a variable named &quot;searchResultsList&quot; inside its instance. You can get it from there. Also please hide the progress bar now [<strong>MVC</strong>]</p>\n<p><em>View</em>: Thank you very much <em>Presenter</em> [<strong>MVP</strong>]</p>\n<p><em>View</em>: Thank you &quot;Controller&quot; [<strong>MVC</strong>]\n(Now the <em>View</em> is questioning itself: How should I present the results I get from the <em>Model</em> to the user? Should the production year of the movie come first or last...? Should it be in a vertical or horizontal list? ...)</p>\n<p>In case you\'re interested, I have been writing a series of articles dealing with app architectural patterns (MVC, MVP, MVVP, clean architecture, ...) accompanied by a Github repo <a href="http://www.digigene.com/android-architecture-wolfkcats" rel="noreferrer">here</a>. Even though the sample is written for android, the underlying principles can be applied to any medium.</p>\n'}, {'answer_id': 56069653, 'author': 'Jboy Flaga', 'author_id': 1451757, 'author_profile': 'https://Stackoverflow.com/users/1451757', 'pm_score': 3, 'selected': False, 'text': '<p>I think this image by Erwin Vandervalk (and the accompanying <a href="https://blogs.msdn.microsoft.com/erwinvandervalk/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns/" rel="noreferrer">article</a>) is the best explanation of MVC, MVP, and MVVM, their similarities, and their differences. The <a href="https://blogs.msdn.microsoft.com/erwinvandervalk/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns/" rel="noreferrer">article</a> does not show up in search engine results for queries on "MVC, MVP, and MVVM" because the title of the article does not contain the words "MVC" and "MVP"; but it is the best explanation, I think. </p>\n\n<p><img src="https://i.stack.imgur.com/Y82D3.png" alt="image explaining MVC, MVP and MVVM - by Erwin Vandervalk"></p>\n\n<p>(The <a href="https://blogs.msdn.microsoft.com/erwinvandervalk/2009/08/14/the-difference-between-model-view-viewmodel-and-other-separated-presentation-patterns/" rel="noreferrer">article</a> also matches what Uncle Bob Martin said in his one of his talks: that MVC was originally designed for the small UI components, not for the architecture of the system)</p>\n'}, {'answer_id': 57860199, 'author': 'Chinmai Kulkarni', 'author_id': 6209277, 'author_profile': 'https://Stackoverflow.com/users/6209277', 'pm_score': 2, 'selected': False, 'text': '<p>In a few words,</p>\n<ul>\n<li>In MVC, View has the UI part, which calls the controller which in turn calls the model &amp; model in turn fires events back to view.</li>\n<li>In MVP, View contains UI and calls the presenter for implementation part. The presenter calls the view directly for updates to the UI part.\nModel which contains business logic is called by the presenter and no interaction whatsoever with the view. So here presenter does most of the work :)</li>\n</ul>\n'}, {'answer_id': 58501778, 'author': 'Hugo Rafael Azevedo', 'author_id': 6065987, 'author_profile': 'https://Stackoverflow.com/users/6065987', 'pm_score': 2, 'selected': False, 'text': '<p>You forgot about <strong>Action-Domain-Responder</strong> (<a href="https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder" rel="nofollow noreferrer">ADR</a>).</p>\n\n<p>As explained in some graphics above, there\'s a direct relation/link between the <strong>Model</strong> and the <strong>View</strong> in MVC.\nAn action is performed on the <strong>Controller</strong>, which will execute an action on the <strong>Model</strong>. That action in the <strong>Model</strong>, <strong>will trigger a reaction</strong> in the <strong>View</strong>.\nThe <strong>View</strong>, is always updated when the <strong>Model</strong>\'s state changes.</p>\n\n<p>Some people keep forgetting, that MVC <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#History" rel="nofollow noreferrer">was created in the late 70"</a>, and that the Web was only created in late 80"/early 90".\nMVC wasn\'t originally created for the Web, but for Desktop applications instead, where the Controller, Model and View would co-exist together.</p>\n\n<p>Because we use web frameworks (<em>eg:. Laravel</em>) that still use the same naming conventions (<em>model-view-controller</em>), we tend to think that it must be MVC, but it\'s actually something else.</p>\n\n<p>Instead, have a look at <a href="https://en.wikipedia.org/wiki/Action%E2%80%93domain%E2%80%93responder" rel="nofollow noreferrer">Action-Domain-Responder</a>.\nIn ADR, the <strong>Controller</strong> gets an <strong>Action</strong>, which will perform an operation in the <strong>Model/Domain</strong>. So far, the same.\nThe difference is, it then collects that operation\'s response/data, and pass it to a <strong>Responder</strong> (<em>eg:. <code>view()</code></em>) for rendering.\nWhen a new action is requested on the same component, the <strong>Controller</strong> is called again, and the cycle repeats itself.\nIn ADR, there\'s <strong>no connection</strong> between the Model/Domain and the View (<em>Reponser\'s response</em>).</p>\n\n<p><strong>Note:</strong> Wikipedia states that "<em>Each ADR action, however, is represented by separate classes or closures.</em>". This is <strong>not</strong> necessarily true. Several Actions can be in the same Controller, and the pattern is still the same.</p>\n\n<p><a href="/questions/tagged/mvc" class="post-tag" title="show questions tagged &#39;mvc&#39;" rel="tag">mvc</a> <a href="/questions/tagged/adr" class="post-tag" title="show questions tagged &#39;adr&#39;" rel="tag">adr</a> <a href="/questions/tagged/model-view-controller" class="post-tag" title="show questions tagged &#39;model-view-controller&#39;" rel="tag">model-view-controller</a> <a href="/questions/tagged/action-domain-responder" class="post-tag" title="show questions tagged &#39;action-domain-responder&#39;" rel="tag">action-domain-responder</a></p>\n'}, {'answer_id': 69731196, 'author': 'Mostafa Wael', 'author_id': 14043328, 'author_profile': 'https://Stackoverflow.com/users/14043328', 'pm_score': 3, 'selected': False, 'text': '<h1>MVC (Model-View-Controller)</h1>\n<p>In MVC, the Controller is the one in charge! The Controller is triggered or accessed based on some events/requests then, manages the Views.</p>\n<p>Views in MVC are virtually stateless, the Controller is responsible for choosing which View to show.</p>\n<p><strong>E.g.:</strong> When the user clicks on the “Show MyProfile” button, the Controller is triggered. It communicates with the Model to get the appropriate data. Then, it shows a new View that resembles the profile page. The Controller may take the data from the Model and feed it directly to the View -as proposed in the above diagram- or let the View fetch the data from the Model itself.</p>\n<h1>MVP (Model-View-Presenter)</h1>\n<p>In MVP, the View is the one in charge! each View calls its Presenter or has some events that the Presenter listens to.</p>\n<p>Views in MVP don’t implement any logic, the Presenter is responsible for implementing all the logic and communicates with the View using some sort of interface.</p>\n<p><strong>E.g.:</strong> When the user clicks the “Save” button, the event handler in the View delegates to the Presenter’s “OnSave” method. The Presenter will do the required logic and any needed communication with the Model then, calls back the View through its interface so that the View can display that the save has been completed.</p>\n<h1>MVC vs. MVP</h1>\n<ul>\n<li>MVC doesn’t put the View in charge, Views act as slaves that the Controller can manage and direct.</li>\n<li>In MVC, Views are stateless contrary to Views in MVP where they are stateful and can change over time.</li>\n<li>In MVP, Views have no logic and we should keep them dumb as possible. On the other hand, Views in MVC may have some sort of logic.</li>\n<li>In MVP, the Presenter is decoupled from the View and talks to it through an interface. This allows mocking the View in unit tests.</li>\n<li>In MVP, Views are completely isolated from the Model. However, in MVC, Views can communicate with the Model to keep it up with the most\nup-to-date data.</li>\n</ul>\n<p><a href="https://i.stack.imgur.com/Yttsn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yttsn.png" alt="enter image description here" /></a></p>\n'}]
['https://Stackoverflow.com/questions/2056', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/358/']