Sorry if this has already been asked before but I couldn't find any help.
I was wondering if anyone had any good examples of complex winforms created using the supervising controller MVP pattern. I have read a lot of examples but they are really only simple and only deal with having one form and one model.
What I am looking for is a example that shows how to pass data from one view to another and where the communication lines should be and what should be bound to what.
Say I have UI like this: alt text http://img12.imageshack.us/img12/2683/layoutcroped.jpg
Sorry for the dodgy UI mockup. basically each user control has it own presenter and modal layer object.
What I need to do is take the input of the textbox on user control 1, get the right item from the database using the a service object(in presenter for user control 1) and pass it as the modal to user control 2.
My question is: Do I pass the model to the user control 2 via the view interface or into its presenter?
Sorry if this is a bit hard to understand, I just keep seeing people saying you can use forms with user controls that use MVP pattern but can't find any examples about how to pass around data between the two.
EDIT: I have draw up two different was I think I could do this:
and
I think Ex1 is the better one as it still leaves the presenters in charge. To do what they want.
What do you think?
Thanks.
The way I would approach this is from an event oriented, publish/subscribe approach.
The pattern goes something like this:
The user clicking the Edit button on the first view fires off an event (you could call it a command) with a single parameter (the ID, value of the textbox in this case). Call the event "EditRequested", say. This is the "publish" of the event, telling anyone who wants to know that this has occurred and the details. The actual publish might be done in the controller/presenter.
The controller/presenter for the second view listens for the above event and, when the event fires, acts accordingly, loading the data and switching to edit mode using the event parameter (ID). This is the "subscribe" part of the pattern.
Ideally this would be done using an event aggregator (CAB provides one as does Prism) but you can probably do something manually for a single case. The event aggregator removes the need for the publisher and subscriber having to be aware of each other, improving loose coupling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With