1

I am about to start the development of a medium-sized CRUD RCP-based application and I intend to use the MVP (model view presenter) pattern.

I understand that the main difference between the MVP and the MVC is that the presenter updates the view whereas the controller doesn't.

What I really don't understand is who has a reference to what in this pattern. In one tutorial, I read that the view has a presenter instance variable (see: http://www.logicdevelopment.net/blog/?p=16). But the presenter also needs to have a reference to the view. Doesn't it? Is all of this correct?

Can anyone please provide explanations of how a typical MVP application is structured in terms of who owns references to what?

code added from the view:

button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                // can we reference the presenter here? how?
            }
        });

Using information from link provided below I came up with the diagram below. Notice that the view has a reference to the presenter and vice versa (see option one from here):

passive view diagram

Community
  • 1
  • 1
balteo
  • 23,602
  • 63
  • 219
  • 412

1 Answers1

2

Actually, there are two different flavors of MVP. The MVP pattern was described by Fowler in 2004 and he retired it in 2006 by splitting the pattern into supervising conroller (sc) and Passive View (pv). In sc, the view is bound to the model and in pv not, in pv the view is only changed by the presenter directly.

My answer to Does Presenter in Model-View-Presenter create views? has some more details.

Community
  • 1
  • 1
Marijn
  • 10,367
  • 5
  • 59
  • 80
  • Thanks Marijn. I have added code in my post. To refine my question: what should go `\\here` in terms of the presenter/controller? Can the view have a reference to the presenter/controller for instance? I don't seem to see anything indicating this in either of the sc or pv... – balteo Nov 24 '11 at 09:25
  • A view can have events, that the presenter subscribes to. You can also have the view hold a reference to the presenter (knowing only of its interface type). In the latter situation, vuew and presenter hold a reference to each other, which leads to the question [Does Presenter in Model-View-Presenter create views?](http://stackoverflow.com/questions/6248992/does-presenter-in-model-view-presenter-create-views/6431252#6431252). – Marijn Nov 24 '11 at 09:39
  • Ok. Can you confirm only option 1 of you post applies here in the case of RCP - because the creation of views is not really under my control? – balteo Nov 24 '11 at 09:50
  • Confirmed, assuming that the creation of the view is not under your control and with the disclaimer that I know close-to-nothing about rcp. E.g. RCP might provide you with an option to interact with the "view creation bootstrapper", which would leave option 3 open too. I applied MVP to winforms applications, where I encountered similar problems: namely that winform infrastructure places some requirements on construction and destruction of the view. In those cases, creating my own bootstrapper for the mvp triad really helped. – Marijn Nov 24 '11 at 10:01