1

first of all, please forgive me if I get the terminology wrong. Terminology is important, but similar concepts are often expressed with different terms. Let's say I have two, not well defined, "entities" in my presentation layer that must use the same data retrieved from the Service layer. What does entities should be?

Should these entities be both presenters of MVPs? If so, does it make sense to create two MVP triads that handles somehow the same data (but of course in a different way)?

Is it perhaps better to have one presenter and multiple views? Or maybe it means that the Model is too bloated and it should be split into different models?

Although I am sure there is a design issue somewhere in our code, I noticed that we have several classes, that cannot even be defined as presenters, using independently the same data from the service layer and this bothers me a lot.

sebas
  • 1,045
  • 12
  • 27
  • Load them once from the Service layer, use the retrieved references where neccessary. So 1 Model and any Count of Presenters and Views – TGlatzer Mar 04 '15 at 12:35
  • so you mean injecting the same model inside different MVPs – sebas Mar 04 '15 at 12:52

1 Answers1

2

In MVP, the Presenter is tighly coupled to each View (since it controls the behaviour of the View). That means if you have multiple Views that differ substantially, then you need to have also multiple Presenters.

But neither the View nor the Presenter hold any data. The Model is the representation of the current state of the data in the application.

So if the data you fetch from the service layer is handled in the same way for both cases (but just presented differently), then you should have one Model which is referenced by both Presenters.

But if what you fetch is just some kind of "raw" data which gets processed in a very different way, then you probably should also create an own Model for each Presenter/View. The model can reference the fetched data which can be held somewhere in the Service layer or a higher level model object.

jhyot
  • 3,733
  • 1
  • 27
  • 44
  • thanks, just one note, if I remember correctly there are multiple possible implementation of MVP. I am quite sure one was contemplating the option to have multiple views managed by one Presenter. However I agree that it could not make sense as well. – sebas Mar 06 '15 at 13:23
  • 1
    There might be other sources, by I am referring to Fowler's definitions: http://martinfowler.com/eaaDev/ModelViewPresenter.html. You can see there that MVP has been split by him into Supervising Controller and Passive View. It is clear that in Passive View the Controller/Presenter is tighly coupled to the View since the View does nothing. But even in Supervising Controller you find this sentence from him: "[...]the controller is still closely coupled to its screen, needing a pretty intimate knowledge of the details of the screen." – jhyot Mar 06 '15 at 13:38