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

Sanendak

12/29/2021, 4:19 PM
Hello everyone! I have a question about collecting data from multiple data sources into one list. I have two sources: remote and local. Models for these items almost the same except several fields. It's okay to merge them into one source for viewmodel? In that case new shared model will have several null fields. Or I should collect data separately and not merge models? In the list local items always placed first. Thanks.
1
m

Max Ferrier

12/29/2021, 6:00 PM
You can get data from remote, save them into your db and only work with local data
👍 1
👀 1
w

Will Shelor

12/30/2021, 10:17 AM
Assuming you're using Kotlin, this sounds like a great use case for a sealed class. Have a sealed class representing your data (possibly with the common values between the two of them), then extend it with local and remote.
2
👍 2
k

K Merle

12/30/2021, 7:07 PM
In that case new shared model will have several null fields
Would possibly be a smell, as your contract does not fit. If you merge them, can you have a domain model that will not contain unnecessary properties?
m

McEna

01/02/2022, 12:57 AM
To the view, the source of the data (local/remote) should not matter. Only the nature of the data should. Data of X nature should correspond to an X class. Unless you are showing different, yet similar things (like dogs and cats), the only difference should be the degree of completion between different instances of the object.
And you should have an unified data layer where the completion happens.
👍 1
3 Views