4
votes

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:

  1. The views construct their presenters, and window_view constructs widget_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 the window_presenter would access the widget_presenter. Adding a widget_presenter setter to window_presenter for window_view to fill in doesn't feel right to me.
  2. Eliminate the communication line between the two presenters. window_presenter talks to widget_presenter through window_view. This too doesn't seem ideal to me because it requires adding code to window_view merely for the communication between window_presenter and widget_presenter. It also only allows one way communication, and it also adds fat to widget_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.

1

1 Answers

0
votes

I found this article that might help:

http://martinfowler.com/eaaDev/uiArchs.html

In particular, it looks like you are talking about the "classical" mvc, where each widget is a view with its own controller. I think the article talks about a "forms" view of the world, were each "form" is a collection of views, and there is only one controller or presenter. I think MVP falls under the "forms" view, so typically one presenter per form.