https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
j

jermainedilao

08/26/2019, 2:24 AM
Hi! Im doing Clean Architecture pattern in my app. Let’s say I have a
Product
item. Now, that
Product
must contain
category
and
subcategory
. Currently, the API only returns the
guid
of the category and subcategory. Now the question is. Should the mapping of getting the
category
and
subcategory
from the API and putting them inside the
Product
class be inside the
data
module? OR I can put it inside my
GetProductUseCase
? If I choose the latter. So my usecase would look something like this:
Copy code
getProducts()
    .zip(repo.getCategory(), repo.getSubCategory())
    .flatMap { 
        product.category = category
        product.subcategory = subcategory
     }
What’s the best practice for this?
e

Eric Martori

08/26/2019, 11:25 AM
Use cases should deal only with domain entities. The fact that the API returns
guids
is an implementation detail of the API and should be dealt by the
ProductRepository
implementation that deals with it. If in the future the API changes and starts returning nested elements your use case should remain the same and only de repository should change
💯 3
j

jermainedilao

08/27/2019, 12:32 AM
Makes sense. Thanks for the input @Eric Martori! 💯