{"id":307,"date":"2007-10-18T02:08:00","date_gmt":"2007-10-18T02:08:00","guid":{"rendered":"https:\/\/staging.infragistics.com\/blogs\/?p=307"},"modified":"2025-02-19T13:47:24","modified_gmt":"2025-02-19T13:47:24","slug":"mvc-or-mvp","status":"publish","type":"post","link":"https:\/\/www.infragistics.com\/blogs\/mvc-or-mvp","title":{"rendered":"MVC or MVP Pattern \u2013 Whats the Difference?"},"content":{"rendered":"\n<p>Over the years I have mentored many developers on using design patterns and best practices. One question that keeps coming up over and over again is: What are the differences between the Model View Controller (MVC) and Model View Presenter (MVP) patterns?<\/p>\n\n\n\n<p>Surprisingly the answer is more complex than what you would suspect. Part of reasons I think many developers shy away from using either pattern is the confusion over the differences.<\/p>\n\n\n\n<p>Before we dig into the differences let\u2019s examine how the patterns work and the key benefits to using either one. Both (MVC &amp; MVP) patterns have been used for several years and address a key OO principal namely separation of concerns between the UI and the business layers. There are a number of frameworks is used today that based on these patterns including&nbsp;<a class=\"\" href=\"http:\/\/struts.apache.org\/\" rel=\"noopener\">JAVA Struts<\/a>,&nbsp;<a class=\"\" href=\"http:\/\/www.rubyonrails.org\/\" rel=\"noopener\">ROR<\/a>,&nbsp;<a class=\"\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa480482.aspx\" rel=\"noopener\">Microsoft Smart Client Software Factory (CAB)<\/a>,&nbsp;<a class=\"\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/bb264518.aspx\" rel=\"noopener\">Microsoft Web Client Software Factory<\/a>, and the recently announced&nbsp;<a class=\"\" href=\"http:\/\/weblogs.asp.net\/scottgu\/archive\/2007\/10\/14\/asp-net-mvc-framework.aspx\" rel=\"noopener\">ASP.Net MVC framework<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"model-view-controller-mvc-pattern\">Model View Controller (MVC) Pattern<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/users.infragistics.com\/tsnyder\/MVC%20View.jpg\" alt=\" Model View Controller (MVC) Pattern\" title=\"Model View Controller (MVC) Pattern\"\/><\/figure>\n\n\n\n<p>The MVC pattern is a UI presentation pattern that focuses on separating the UI (View) from its business layer (Model). The pattern separates responsibilities across three components: the view is responsible for rending UI elements, the controller is responsible for responding to UI actions, and the model is responsible for business behaviors and state management. In most implementations, all three components can directly interact with each other and in some implementations, the controller is responsible for determining which view to display (<a class=\"\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms978723.aspx\" rel=\"noopener\">Front Controller Pattern<\/a>),<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"model-view-presenter-mvp-pattern\">Model View Presenter (MVP) Pattern<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/users.infragistics.com\/tsnyder\/MVP%20View.jpg\" alt=\" Model View Presenter (MVP) Pattern\" title=\"Model View Presenter (MVP) Pattern\"\/><\/figure>\n\n\n\n<p class=\"CxSpFirst\">The MVP pattern is a UI presentation pattern based on the concepts of the MVC pattern. The pattern separates responsibilities across four components: the view is responsible for rending UI elements, the view interface is used to loosely couple the presenter from its view, the presenter is responsible for interacting between the view\/model, and the model is responsible for business behaviors and state management. In some implementations, the presenter interacts with a service (controller) layer to retrieve\/persist the model. The view interface and service layer are commonly used to make writing unit tests for the presenter and the model easier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"key-benefits\">Key Benefits<\/h2>\n\n\n\n<p>Before using any pattern a developer needs to consider the pros and cons of using it. There are a number of key benefits to using either the MVC or MVP pattern (See the list below). But, there also a few drawbacks to consider. The biggest drawbacks are adding complexity and learning curve. While the patterns may not be appropriate for simple solutions; advance solutions can greatly benefit from using the pattern. I\u2019m my experience a have seen a few solutions eliminate a large amount of complexity but being refactored to use either pattern.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Loose coupling \u2013 The presenter\/controller are an intermediary between the UI code and the model. This allows the view and the model to evolve independently of each other.<\/li>\n\n\n\n<li>Clear separation of concerns\/responsibility<\/li>\n<\/ul>\n\n\n\n<p>o&nbsp;&nbsp;&nbsp;&nbsp;UI (Form or Page) \u2013 Responsible for rending UI elements<\/p>\n\n\n\n<p>o&nbsp;&nbsp;&nbsp;&nbsp;Presenter\/controller \u2013 Responsible for reacting to UI events and interacts with the model<\/p>\n\n\n\n<p>o&nbsp;&nbsp;&nbsp;&nbsp;Model \u2013 Responsible for business behaviors and state management<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Test Driven<\/strong> \u2013 By isolating each major component (UI, Presenter\/controller, and model) it is easier to write unit tests. This is especially true when using the MVP pattern which only interacts with the view using an interface.<\/li>\n\n\n\n<li><strong>Code Reuse<\/strong> \u2013 By using a separation of concerns\/responsible design approach you will increase code reuse. This is especially true when using a full-blown domain model and keeping all the business\/state management logic where it belongs.<\/li>\n\n\n\n<li><strong>Hide Data Access<\/strong> \u2013 Using these patterns forces you to put the data access code where it belongs in a data access layer. There a number of other patterns that typically works with the MVP\/MVC pattern for data access. Two of the most common ones are repository and unit of work. (See Martin Fowler \u2013 Patterns of Enterprise Application Architecture for more details)<\/li>\n\n\n\n<li><strong>Flexibility\/Adaptable<\/strong> \u2013 By isolating most of your code into the presenter\/controller and model components your code base is more adaptable to change. For example, consider how much UI and data access technologies have changed over the years and the number of choices we have available today. A properly design solution using MVC or MVP can support multi UI and data access technologies at the same time.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"key-differences\">Key Differences<\/h2>\n\n\n\n<p>So what really are the differences between the MVC and MVP pattern. Actually, there are not a whole lot of differences between them. Both patterns focus on separating responsibility across multi components and promote loosely coupling the UI (View) from the business layer (Model).&nbsp;&nbsp;The major differences are how the pattern is implemented and in some advanced scenarios, you need both presenters and controllers.<\/p>\n\n\n\n<p>Here are the key differences between the patterns:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MVP Pattern<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The view is more loosely coupled to the model. The presenter is responsible for binding the model to the view.<\/li>\n\n\n\n<li>Easier to unit test because interaction with the view is through an interface<\/li>\n\n\n\n<li>Usually, view presenter map one to one. Complex views may have multi presenters.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">MVC Pattern<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Controllers&nbsp;are based on behaviors and can be shared across views<\/li>\n\n\n\n<li>Can be responsible for determining which view to display (<a class=\"\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms978723.aspx\" rel=\"noopener\">Front Controller Pattern<\/a>)<\/li>\n<\/ul>\n\n\n\n<p class=\"CxSpFirst\">Hopefully, you found this post interesting and it helped clarify the differences between the MVC and MVP pattern. If not, do not be discouraged patterns are powerful tools that can be hard to use sometimes. One thing to remember is that a pattern is a blueprint and not an out of the box solutions. Developers should use them as a guide and modify the implementation according to their problem domain.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/download.infragistics.com\/marketing\/Blog-in-content-ads\/Ultimate\/Blog-incontent-Ultimate-650x200.jpg\" alt=\" \"\/><\/figure>\n\n\n\n<p class=\"CxSpLast\"><span style=\"font-size: 10pt;\"><a href=\"\/downloads\/request\/00000000-0000-0000-0000-000000005656\"><span style=\"color: black; font-family: Arial, sans-serif; line-height: 115%;\"><\/span><\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the years I have mentored many developers on using design patterns and best practices. One question that keeps coming up over and over again is: What are the differences between the Model View Controller (MVC) and Model View Presenter (MVP) patterns?<\/p>\n","protected":false},"author":103,"featured_media":1479,"comment_status":"publish","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to"],"_links":{"self":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/users\/103"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":3,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":1964,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/307\/revisions\/1964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media\/1479"}],"wp:attachment":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}