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_view
constructswidget_view
. But then,window_view
needs extra parameters in its constructors, parameters it shouldn't care about, merely to instantiate the presenter. I also am not sure how thewindow_presenter
would access thewidget_presenter
. Adding awidget_presenter
setter towindow_presenter
forwindow_view
to fill in doesn't feel right to me. - Eliminate the communication line between the two presenters.
window_presenter
talks towidget_presenter
throughwindow_view
. This too doesn't seem ideal to me because it requires adding code towindow_view
merely for the communication betweenwindow_presenter
andwidget_presenter
. It also only allows one way communication, and it also adds fat towidget_view
to 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.