0

This question is build on top of a previously asked question: MVP Communication between presenters?

I am implementing the pattern outlined in the previous post. However I've run into an issue when trying to retrieve state from Presenter B based on some event in Presenter A.

For example, Presenter A responds to a view event, SaveButtonClicked.

Presenter A needs to get some state from Presenter B's view, View B.

So far what I've tried is:

class PresenterA
{
    void PresenterA()
    {
        EventHub.Register(EventType.SendStateToPresenterA, HandleSendStateToPresenterA);
    }
   void HandleSaveClick(int productId)
   {
      EventHub.Publish(EventType.GetStateFromPresenterB, productId);
   }

   void HandleSendStateToPresenterA(string state)
   {
       // save to db
   }
}

class PresenterB
{
    void PresenterB
    {
       EventHub.Register(EventType.GetStateFromPresenterB, HandleGetStateFromPresenterB);
    }

    public void HandleProductChanged(int state)
    {
       EventHub.Publish(EventType.SendStateToPresenterA, "I am state!");
    }
}

The problem with this approach is that it is overly complex if I have more than 2 presenters.

What are some ways to handle this?

Community
  • 1
  • 1
drizzie
  • 3,351
  • 2
  • 27
  • 32

1 Answers1

0

I have found that the situation doesn't actually warrant a separate view / presenter for the Presenter B. It belongs in View A / Presenter A.

drizzie
  • 3,351
  • 2
  • 27
  • 32