I'm trying to figure out how MVP should be implemented at the
UserControl level. I thought I had it, but I ended up reading a blog post that pretty much shut me down. Now I'm back at the start and with no idea how to proceed.
Let's say my
UserControl is something simple like two
TextBoxes and a
ComboBox. This gets invoked from a main form (which has its own View and Presenter). Now, the way I understand MVP is that the Main Form Presenter is supposed to invoke a second presenter to handle all communication with the UserControl that gets dropped there.
And this is where I get completely lost. My past implementations of
UserControls (before I learned MVP) always incorporated the logic behind the control (e.g.
ComboBox selection will change text label related to
TextBox1). As such, implementation of the
UserControl is done by dragging it onto the designer, and then calling commands like
In any third-party
UserControl, all commands to the
UserControl are performed by commands to the control. There is no "presenter" that needs to be invoked, for instance, when I drop a
ComboBox, or a
ListView, or any other WinForms control onto my form. Yet they have internal logic that dictates how they display, and in the essence of testing, it should have a "presenter" separation to it somewhere.
I thought that a good solution would be that the constructor of my
UserControl would create a Presenter. Any commands to the
UserControl would delegate straight to the Presenter. This would allow my
UserControl to have its own presentation logic separated from its "view", such that I can test it, and such that the implementer (the Main Form) need only drop in the
UserControl and perform data sends and receives as part of its local presentation logic. The
UserControl has its own presentation logic left invisible to the implementer.
And just when I thought I understood it all, I find out that it's bad practice (The Self-Aware View). So I plead with people who understand this better than I: How do I construct a
UserControl that keeps its presentation logic invisible to the end-user, such that I don't have to construct the wrapping presenter in my Main Form, without violating the principles that Matt Wynne discusses in the linked post above?
Or am I completely misunderstanding the concept of MVP here?