What is the best way to coordinate children's views in MVP?

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();
    }
}
+5
source share
3 answers

. . , Prism/library.

:

public class ChildViewOne {
    private IEventAggregator evtAggregator;

    public ChildViewOne(IEventAggregator evtAggregator) {
        this.evtAggregator = evtAggregator;
    }

    private void OnEventOccured(){
        evtAggregator.GetEvent<EventOccured>().Publish();
    }
}

publish class ChildViewTwo {
    private IEventAggregator evtAggregator;

    public ChildViewTwo(IEventAggregator evtAggregator) {
     evtAggregator.GetEvent<EventOccured>().Subscribe(OnEventOccured);
    }

    private void OnEventOccured() {
        // Do something here...
    }
}

EDIT: winforms. ,

0

. , ?

, . MVP, ?

0

IChildView SiblingView ( - , - ). , SetSiblingView(). . OnSiblingEventFired().

, , , , , , .

, , , MVC.

0

All Articles