sebas
sebas

Reputation: 1085

What to do when data from the service layer needs to be shared between different presentation entitites

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.

Upvotes: 1

Views: 107

Answers (1)

jhyot
jhyot

Reputation: 3955

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.

Upvotes: 2

Related Questions