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

Ofir Bar

03/10/2020, 8:52 AM
Hey guys. Regarding the single responsibility pattern, for example when working with Retrofit and Room, I wonder if you have “exceptions” to that rule. I usually fetch data from the network, save it to the local cache, and then the UI gets data from the local DB. However, some parts of my app intensively depends on data from the network, imagine an app like buying and selling stuff like ebay. I expect the data to change frequently. In this case it doesn’t make that sense to cache my data at all, as it might change, so would you feed the UI directly from the network in this case?
k

Kirill Prybylsky

03/10/2020, 8:56 AM
I think this should be decided at repository level, so your presenter/viewmodel will get data anyway. So keep it simple and use data from network. But still map to domain model 😉
2
o

Ofir Bar

03/10/2020, 8:58 AM
Thanks @Kirill Prybylsky, what do you mean by still mapping to the domain model?
k

Kirill Prybylsky

03/10/2020, 9:00 AM
For example: UserResponse is network model, so in your domain module/package there should be User model, which will be mapped from UserResponse.
o

Ofir Bar

03/10/2020, 9:07 AM
Oh, the project I am currently working on doesn’t do that and there is only one object (both for the network and domain) In what it helped you separating them?
k

Kirill Prybylsky

03/10/2020, 9:17 AM
Low coupling
3
You can replace whole network/db layer within an hour.
🍻 1
👍 1
f

florent

03/10/2020, 10:09 AM
Hehe it seems that no body knows that you can cache data on the network layer
🤔 1
a

Anastasia Finogenova

03/10/2020, 6:18 PM
You should make these decisions where to get data at the Repositoty level, you can do either cache checks and then fetch data or fetch data and return it as is or fetch and then cache in case of network outages , your view and viewmodel should be agnostic from these "decisions"
👍 2
2 Views