Tuesday 5 July 2011

Understanding the MVP Pattern

Taken from the examples given in the Fisharoo project (Book: ASP.Net 3.5 Social Networking)

View
  • The ASP.Net code
  • The code behind (or is it code beside?) files 
    • Note that the code behind does not do any decision making...it only handles display logic like events and then calls the methods of the Presenter instance to defer the decision making.
  • An interface - implemented by the code behind and passed to the Presenter, enabling the Presenter access to methods/properties/et al of the View
    • This Interface is what allows us to swap out the UI whilst maintaining the Presenter and Model
    • That is: as long as the View (new UI) implements the Interface, it can continue to use the Presenter (which in turns use the Model)
  • Responsible for handling the events from the page such as button clicks
  • Also takes care of simple display issues...such as?
  • Provides methods to the Presenter to enable it to toggle the state of various display items
Presenter
  • Often does not include a lot of logic either
  • Quick to pass on the major logic to the Model, often via Services
  • The Presenter will populate Business Entities with values passed to it from the View and then pass those Entities onto methods in the Model
  • The Presenter will use information passed to it from the View to perform validation and redirection
  • The Presenter will also use information passed back to it from the Model to decide what is the next best course of action eg Redirect, Display Message, etc.

    No comments:

    Post a Comment