Question

Say you have multiple MVP triads in your application (WinForms .NET 2.0 app) and each triad looks after one area of responsibility. What is your preferred way of coordinating the communication between the MVP triads?

Option 1 A coordinator object that "has" each model and looks after the coordination through subscribing to the necessary events in each and then deciding what model methods to call in what scenarios.

Worry that this may be a "god" class.

Option 2 A Presenter "has" another presenter and when something of interest happens in the model, the presenter uses the other presenter to move communication along.

Worry that the presenters should not have a public interface (Presenter-first approach) and this breaks that.

I am just wondering what other people have done to solve this problem in a scalable OO fashion. What if I add another MVP triad? How hard will it be to fit that into my coordinator? There must be some good examples of how to manage multiple MVP triads in a WinForms app?

Was it helpful?

Solution

Not to be vague... but it depends. The two approaches I've used in the past:

  1. Use an Event Aggregator pattern, and have the individual presenters fire off events that other presenters can handle. e.g. PresenterA does: events.Raise<MyEvent> () and PresenterB implements: IHandler<MyEvent> and reacts accordingly in its public void Handle (MyEvent @event) method.
  2. Use a shared model that is injected into the presenters that need to be coordinated. For example, if one presenter handles selection of a given Foo, and the other presenter needs to update a details panel with Foo details, I might use an IFooSelection state model and inject that into both presenters that need to coordinate the concept of 'current selection'.

The interface:

public interface IFooSelection {
    public event EventHandler Changed;
    Foo Selected { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top