I've been looking in the MVP pattern for a while, and managed to create some simple MVP-compliant applications.
I am now trying to apply the pattern to a more complex application, and I have some doubts on the best way of doing that.
My application has a single WinForm, with two buttons for loading two different kinds of data. My view interface looks like the following:
interface IView_MainForm
{
// Load input
//
event EventHandler<InputLoadEventArgs> LoadInput_01;
event EventHandler<InputLoadEventArgs> LoadInput_02;
bool Input01_Loaded { get; set; }
bool Input02_Loaded { get; set; }
}
The IView is referenced in my presenter via constructor injection:
public Presenter_MainForm(IView_MainForm view)
{
this.View = view;
this.View.LoadInput_01 += new EventHandler<InputLoadEventArgs>(OnLoadInput_01);
this.View.LoadInput_02 += new EventHandler<InputLoadEventArgs>(OnLoadInput_02);
}
So far, so good. When the user clicks any of the two buttons for loading data, a LoadInput_## event is raised, the Presenter is handling it, checks the input for errors and structures it according to my data model.
My next step would be displaying the processed data back in the View.
I'm striving to keep my View as passive and "dumb" as possible, assuming it knows nothing of the Presenter (it doesn't subscribe to its events, the Presenter sends data to the View by calling IView methods instead), let alone of the Model.
How am I supposed to populate a control like a TreeView, if the View has no idea of what the data model looks like?
Also, am I getting the whole MVP thing right, or is there anything I have missed?
IView_MainForm
? – huMpty duMptyview
won't know what's thedata model
(I'm assuming you meanModel
), how it is supposed to bind itself to data? – MichaelMainForm
) implementsIView_MainForm
, this is how I've been able to implement the MVP pattern at a basic level for now:Presenter
takesIView_MainForm
as parameter in its constructor, subscribes to its events and displays results by calling methods specified in the interface (and implemented byMainForm
). – vi3xView
andModel
know nothing about each other, since it's thePresenter
which handles user events and instructs theView
on how to display data. If myView
already knows what my data looks like, what's the point of MVP in the first place? I could then simply populate my controls by directly referencing myModel
... Am I missing something here? – vi3x