https://kotlinlang.org logo
Title
s

Sagar Suri

01/20/2020, 8:39 AM
Question regarding separation of concern in clean architecture: I have the following layer in my app: 1. UI 2. Presentation 3. Usecase 4. Repository 5. Data layer(Remote & Local data source) Now I get a
JSONArray
from the remote data source. For simplicity the
JSONArray
consist of a list of the following `JSONObject`:
{
 "id": 1,
 "type": "city",
 "url": "<http://xyz.com/berlin.png>",
 "section": "world",
}
In my UI I want to show only list of Images. My UI should not get all a model which consist of
URL
. In which layer should I use a mapper to convert the
ModelEntity
to a
Model
which consists of
URL
only?
f

Francisco Javier Ruiz Rodriguez

01/20/2020, 8:53 AM
I'd do it in Usecase
s

Sagar Suri

01/20/2020, 8:57 AM
Reason being? @Francisco Javier Ruiz Rodriguez Just want to understand the valid points.
f

Francisco Javier Ruiz Rodriguez

01/20/2020, 9:00 AM
Well, if in a future, you wolud like to show a list of images with the name of the city, you have to map it just in usecase, and if you want to reuse the code of the repository layer, you have all the object mapped 😄
👍 1
s

Sagar Suri

01/20/2020, 9:05 AM
Cool, make sense. How do you use presenter? What if I move this mapping logic in presenter? I am confused with the responsiblity of
presenter
and
usecase
now.
t

turastory

01/20/2020, 9:33 AM
Well, I think conceptually there should be no logic in presentation layer, except communications with View. But moving all logics into use case.. would make too much boilderplate, so I usually put simple logics in ViewModel, and heavy logics in use case.
👍🏾 1
s

Sagar Suri

01/20/2020, 9:35 AM
will you consider mapping the entity model to data model a lightweight logic? @turastory
t

turastory

01/20/2020, 9:38 AM
No, because that involves 3rd party, something like network or database. In fact, I think you should put those mappers in data layer, because the json response totally depends on the remote data source.
💯 1
Though I’m not sure about this.. Check out how other guys did. I recommend tivi app of Chris Banes: https://github.com/chrisbanes/tivi
f

Francisco Javier Ruiz Rodriguez

01/20/2020, 9:56 AM
I usually have 3 data model, one for data/repository, one for use case and one for presenter/view, and the one for presenter have only the necesary params for the view, so the view doesn't have any data it doesn't need. In usecase, I normally have all the data the views could need, because the usecase could be used in some parts of the app, but every application is different, so maybe for you is better to map it into presenter 🙂
💯 2
h

Hitender Pannu

01/22/2020, 5:41 AM
Total Agree with @Francisco Javier Ruiz Rodriguez here. The main responsibility of presenter is to "decide and provide" the content to view layer. it can use useCase in your case to get the actual data and create a mapper to provide the required content to view. Generally we have one presenter for one view but use case can be used by multiple presenters.
💯 2