Docstoc

MVC Vs MVP

Document Sample
MVC Vs MVP Powered By Docstoc
					                                   Articles from Jinal Desai
MVC Vs MVP
2012-05-27 17:05:29 Jinal Desai

While surfing for the differences between MVC (Model View Controller) and MVP (Model View Presenter) I
found lots of confusion over the net. Also I found some differences between the two on some sites, but
none of them have complete list of differences. Following is one attempt for compiling almost all the
differences between the two patterns.

   Parameter                      MVC (Model View Controller)             MVP (Model View Presenter)
                                                                        View(UI), Model(Business
                     View(UI), Model(Business Entities/Data),
Structure                                                               Entities/Data), Presenter(UI
                     Controller(UI Business Logic/Request Handling)
                                                                        Business Logic/Request Handling)
                                                                          In MVP Presenter is the supervisor
                     In MVC Controller is the supervisor for responsing
                                                                          for responsing requests from view,
                     requests from View, commanding/altering model
Supervisor                                                                commanding/altering model for
                     for providing entities/data and decide the next view
                                                                          providing entities/data and return
                     to display.
                                                                          user requested view.
Supervisor and                                                     In MVP, Presenter is decoupled
               In MVC, Controller is coupled with View. Controller
View                                                               from view. Presenter talks to view
               is invoking next view through it’s concrete class.
Decoupling                                                         via interface.
                                                                        In MVP, communication between
               In MVC, communication between View and
                                                                        View and Presenter(Supervisor) is
Supervisor and Controller(Supervisor) is one way. View is
                                                                        two way. View is triggering
View           triggering Controller actions, but Controller is not
                                                                        Presenter actions, and after
Communication directly talking to view. It always go through the
                                                                        processing the request Presenter
               Model.
                                                                        updates View through interface.
                                                                       One View is mapped to one
View and                                                               Presenter only, because presentor
                     Multiple Views can be mapped to single controller
Supervisor                                                             is updating View through interface.
                     becuase Model is updating View.
Mappings                                                               So, Presenter must be aware about
                                                                       which view to update/create.
              Passive Model: Employed when Controller is
              exclusively updates Model. The controller modifies
              the model and then informs the view that the
                                                                        Passive Model: The View is as
              model has changed and should be refreshed. The
                                                                        dumb as possible and contains
              model in this scenario is completely independent
                                                                        almost zero logic. The Presenter is
              of the view and the controller, which means that
                                                                        a middle man that talks to the View
              there is no means for the model to report changes
                                                                        and the Model. The View and Model
              in its state. The HTTP protocol is an example of
                                                                        are completely shielded from one
              this. There is no simple way in the browser to get
                                                                        another. The Model may raise
              asynchronous updates from the server. The
                                                                        events, but the Presenter
              browser displays the view and responds to user
                                                                        subscribes to them for updating the
              input, but it does not detect changes in the data on
                                                                        View. In Passive View there is no
              the server. Only when the user explicitly requests
Flavors:                                                                direct data binding, instead the View
              a refresh is the server interrogated for changes.
Passive Model                                                           exposes setter properties which the
              Active Model: The active model is used when the
and Active                                                              Presenter uses to set the data. All
              model changes state without the controller’s
Model                                                                   state is managed in the Presenter
              involvement. This can happen when other
                                                                        and not the View.
              sources are changing the data and the changes
                                                                        Active Model: The Presenter
              must be reflected in the views. Consider a stock-
                                                                        handles user gestures. The View
              ticker display. You receive stock data from an
                                                                        binds to the Model directly through
              external source and want to update the views
                                                                        data binding. In this case it’s the
              when the stock data changes. Because only the
                                                                        Presenter’s job to pass off the
              model detects changes to its internal state when
                 model detects changes to its internal state when
                                                                      Model to the View so that it can bind
                 they occur, the model must notify the views to
                                                                      to it. The Presenter will also contain
                 refresh the display.
                                                                      logic for gestures like pressing a
                 MVC pattern is mostly used with Active Model,
                                                                      button, navigation, etc.
                 otherwise in Passive Model we are again
                 introducing dependency between Model and
                 Controller.
                                                                      Also supports maintainability and
                                                                      extensibility with true Separation of
                 Supports easy maintainability and extensibility with
                                                                      Concerns. View and Presentor is
Advantages       Separation of Concerns. Easy to unit test Model,
                                                                      decoupled so easily unit tested, in
                 View and Controller at some extent.
                                                                      MVC in some scenarios it is difficult
                                                                      to mock test View independently.
                 Best used for developing disconnected web            Best used for rich UI applications.
Usages           applications. i.e. ASP.NET MVC, Struts and Java      i.e. Web Forms/Sharepoint,
                 Web Platforms.                                       Windows Forms.

References
http://nirajrules.wordpress.com/2009/07/18/mvc-vs-mvp-vs-mvvm/
http://stackoverflow.com/questions/2056/what-are-mvp-and-mvc-and-what-is-the-difference
http://joel.inpointform.net/software-development/mvvm-vs-mvp-vs-mvc-the-differences-explained/
http://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP
http://msdn.microsoft.com/en-us/library/ff649643.aspx


           Blog this!

           Bookmark on Delicious

           Digg this post

           Recommend on Facebook

           Share on FriendFeed

           Share on Linkedin

           Share on Orkut

           share via Reddit

           Share with Stumblers

           Share on technorati

           Tweet about it

           Subscribe to the comments on this post

				
DOCUMENT INFO
Description: While surfing for the differences between MVC (Model View Controller) and MVP (Model View Presenter) I found lots of confusion over the net. Also I found some differences between the two on some sites, but none of them have complete list of differences. Following is one attempt for compiling almost all the differences between the two patterns.