Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model View Presenter with multiple views (or layered views) in c#

Tags:

c#

mvp

I have a split container in the left panel is a user control with buttons. In the right panel is an initial user control that will change based on which button is pressed. What I want to know is how does one let the Form with the spilt panel know to paint in view x from the presenter of the button view?

like image 977
Chip Snyder Avatar asked Feb 20 '23 02:02

Chip Snyder


1 Answers

In theory, the Presenter should have access to the Views, in which case the Presenter should be notified about any button clicks from the view in the left panel and then update the Form to show the view in the right panel.

How exactly this is accomplished depends heavily on your specific implementation. Architecture patterns are guidelines... there are no hard and fast rules which one must follow (unless you are using an MVP library of some sort, in which case you will be constrained by that library's implementation).

EDIT: To answer your question below, Chip...

Again, that is wholly dependent on your implementation. In some cases, it may make sense to have one massive Presenter and dozens of views. In other cases, it may make sense to have one presenter for each view. Even if you have multiple presenters, though, you will still need to maintain a hierarchy so that the presenters can talk to one another. So somewhere, at some level, a presenter is going to have knowledge of both the button click and the empty container waiting to be filled, even if that knowledge comes indirectly through another presenter.

EDIT 2: (In response to your updated comment) There are no hard and fast rules, but one common trait among MVP implementations is that the Presenter retains at least partial control. That means that the Presenter must have some level of access to all relevant UI elements. If you nest views within views, then you'll still need to devise a way for the Presenter to interact with them.

like image 167
JDB Avatar answered May 10 '23 08:05

JDB