I have a view class that represents a widget, and an accompanying presenter class. I also have a view class for a window that owns the widget, and an accompanying presenter for the window view. The window manipulates the widget, so I need the window presenter to communicate with the widget presenter. To visualize:
+-------------+ +------------------+
| widget_view |<------>| widget_presenter |
+-------------+ +------------------+
^ ^
| |
| V
+-------------+ +------------------+
| window_view |<------>| window_presenter |
+-------------+ +------------------+
What I'm not sure about is how to construct the objects. I know the MVP architecture doesn't deal with this issue but "leaves it as an exercise for the reader". Things I tried:
- The views construct their presenters, and
window_viewconstructswidget_view. But then,window_viewneeds extra parameters in its constructors, parameters it shouldn't care about, merely to instantiate the presenter. I also am not sure how thewindow_presenterwould access thewidget_presenter. Adding awidget_presentersetter towindow_presenterforwindow_viewto fill in doesn't feel right to me. - Eliminate the communication line between the two presenters.
window_presentertalks towidget_presenterthroughwindow_view. This too doesn't seem ideal to me because it requires adding code towindow_viewmerely for the communication betweenwindow_presenterandwidget_presenter. It also only allows one way communication, and it also adds fat towidget_viewto allow outsiders to communicate with its presenter.
I can imagine the complexity growing exponentially here as window_presenter needs to talk to other presenters, or other presenters need to talk with yet other presenters.
I also thought of adding a mediator object here to absorb all these inter-communications and dependencies, but at this point the whole idea of separating the logic from the presentation starts to feel very costly and very complex. Surely I'm doing something wrong here.