Model View Presenter pattern question
-
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
-
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
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?
-
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?
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
-
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
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.