I am trying to use MVP in WinForms and am confused about how best to handle coordination between child views.
For example, I have a parent view that has two child views. Events in one child view must trigger the action that must be taken by the second view for the child.
Should the parent view control this directly? It seems that I am going around the MVP pattern by doing this.
Or should child views take each other as constructor parameters? In this case, when the event was triggered by the first child view, the second child view will receive the event and then inform the host that something happened? Then the facilitator needs to get data from the first child view (which he does not even know about) in order to talk about what the 2nd child needs to do. This seems confusing, so I feel like something is missing.
Here is some kind of pseudo code for the situation:
public class ParentView : UserControl, IParentView
{
private ChildViewOne childViewOne;
private ChildViewTwo childViewTwo;
private ParentViewPresenter presenter;
private RegisterEvents()
{
childViewOne.EventOccured += new EventHandler(HandleEvent);
}
private void HandleEvent()
{
childViewTwo.DoSomething();
}
}
source
share