Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Model View Presenter pattern question

Model View Presenter pattern question

Scheduled Pinned Locked Moved C#
questioncsharphtmlwinformscom
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Judah Gabriel Himango
    wrote on last edited by
    #1

    I'm trying to wrap my head around this pattern and apply it to some real world designs. One thing I'm not sure about is whether tiny bits of logic should go out of the View (the WinForms control) and into the Presenter. Take the following code for example:

    myMenuItem.MouseUp += MyMenuItemMouseUpHandler;

    void MyMenuItemMouseUpHandler(object sender, MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Right)
    {
    ShowOurContextMenu();
    }
    }

    That is in the View (it's inside a WinForms control class). Since there is logic going on here, it seems maybe the logic part should be rolled out of the View and into the Presenter. Is that right? If that logic should go in the presenter, what would the code look like?

    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

    A 1 Reply Last reply
    0
    • J Judah Gabriel Himango

      I'm trying to wrap my head around this pattern and apply it to some real world designs. One thing I'm not sure about is whether tiny bits of logic should go out of the View (the WinForms control) and into the Presenter. Take the following code for example:

      myMenuItem.MouseUp += MyMenuItemMouseUpHandler;

      void MyMenuItemMouseUpHandler(object sender, MouseEventArgs e)
      {
      if(e.Button == MouseButtons.Right)
      {
      ShowOurContextMenu();
      }
      }

      That is in the View (it's inside a WinForms control class). Since there is logic going on here, it seems maybe the logic part should be rolled out of the View and into the Presenter. Is that right? If that logic should go in the presenter, what would the code look like?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      A Offline
      A Offline
      Andrew Lygin
      wrote on last edited by
      #2

      Hi, Judah. 1. Is ShowOurContextMenu() a part of your IView interface? 2. Does your Presenter know about myMenuItem or this is a private part of your view? 3. Does this behaviour common for all views or it is specific only for the concrete view?

      J 1 Reply Last reply
      0
      • A Andrew Lygin

        Hi, Judah. 1. Is ShowOurContextMenu() a part of your IView interface? 2. Does your Presenter know about myMenuItem or this is a private part of your view? 3. Does this behaviour common for all views or it is specific only for the concrete view?

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        ShowOurContextMenu is not part of the interface, but it easily could be. The presenter does not know about myMenuItem. This behavior is for only one particular view.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        A 1 Reply Last reply
        0
        • J Judah Gabriel Himango

          ShowOurContextMenu is not part of the interface, but it easily could be. The presenter does not know about myMenuItem. This behavior is for only one particular view.

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          A Offline
          A Offline
          Andrew Lygin
          wrote on last edited by
          #4

          Then I think you should leave this menu logic in the specific view and don't burden Presenter with it. Presenter must describe the logic which is common for all views.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups