#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Mvp design pattern - question


    hi,

    When I have a button which only changes something in my view (e.g. such that some text appears if I press it), can I write its whole code in the file with my view or should I include event handling of this button in the presenter? This is problem for me, because I don't know, if the presenter handles all events from the view or only these, which change something in the model?

    Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    62
    Rep Power
    13
    I would say there is no need to put the handling code in the presenter, if it's not required there. The Presenter should subscribe to the View events, but if the event is not related to the model or the application logic, and it's purely related to the the view, then why to handle the event inside the Presenter?

    Another reason to put it in presenter could be to test it. Let's say by replacing the Presenter with a Mock presenter you can test the View.
    To find out everything about design patterns check the Design Patterns Reference on oodesign.com.

    Find and share the best tips, tutorials and howto's for php web developers on the newly started php-html.net community.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2005
    Location
    Bay Area, California
    Posts
    841
    Rep Power
    1682
    The View should contain the event handler that is registered for the UI operations (e.g. on button click). However, the handler should be a dumb callback that delegates the work to the Presenter. This allows the Presenter to be tested seperate from the view (normal unit test) because it has no direct UI coupling. The View is lightweight and dumb, so the heavy-weight integration tests can be kept slim since there is little extra needing to be validated.

    This is a common idiom in MVP for web applications, and the Google I/O Gwt testing talk has a lot of good suggestions that translate across frameworks.
    Core design principles when developing software systems.
    See my open-source project as an example of professional code.
    ---
    The opinions expressed do not represent those of my employer.

IMN logo majestic logo threadwatch logo seochat tools logo