0

I am wondering how you do exchange data or/and events between Presenters in Model-View-Presenter architecture.

I have Activity(View) and Presenter for this View, and Dialog(View) and Presenter for this View. When Activity shows Dialog, Dialog's Presenter is injected to Dialog. I am doing something in Dialog (input text) and submit. This text is seted in presenter, and ... exactly. How to pass this data from Dialog's Presenter to Activity's Presenter?

I used Bus Event (Otto form Square) to send data, but if it is good practice?

Aj 27
  • 2,316
  • 21
  • 29
  • When you're done with any work in dialog, just pass it onto the Activity using an interface. – Debdeep Feb 01 '18 at 06:31
  • but dialog doesn't know what should send. dialog is dump. dialog only knows OK was clicked and informs presenter about it. –  Feb 01 '18 at 06:45
  • You must be transferring the text to dialog presenter. We aren't performing any work on the text, so why pass it on? Instead just pass it directly to the activity or If you're fine with using `EventBus` or `LocalBroadcast`, you may do so. In mvp, though direct interaction between presenters using interfaces is regarded as a bad practice as it increases coupling. – Debdeep Feb 01 '18 at 06:54
  • ok but if it would not be a dialog but other komponent? e.i. fragment and his presenter? –  Feb 01 '18 at 07:14
  • 1
    Same goes for them as well. You'll be using an instance of the interface inside the component and implement that in your activity. – Debdeep Feb 01 '18 at 07:21

1 Answers1

0

The solution is simple - it is the "M" in "MVP". Use your model to sync your data across the presenters. If you need a notifier for data changes, there are plenty of possible solutions:

artkoenig
  • 7,117
  • 2
  • 40
  • 61