https://kotlinlang.org logo
a

Aaron Waller

05/09/2022, 5:39 PM
What are the other use cases of the repository class? I know its used for getting Data from the server or cache but what else is the repository used for? I’m using the MVVM pattern and wonder where to put I/O operations like saving and writing a file. I also have a coin system in my app and I need to access that coin int from every screen in my app (settings, profile, home etc), is the Repository a good place to put it?
a

Andrew Neal

05/09/2022, 5:46 PM
Have you seen the new architecture guidelines? https://developer.android.com/topic/architecture/data-layer I think reading through them, especially the data layer section will give you a better idea about how to structure things.
🙌 1
k

K Merle

05/10/2022, 6:59 AM
Saving and writing files should be treated as writing local DB or external data source. It's your data layer. Your repository should do same operations as before, and use FileService type of classes for it.
s

smilecs

05/10/2022, 2:56 PM
it's more of a consolidation of different sources of data, remote, cache, local etc. Your repo would or should provide easy access to data from different sources as well as make it easy to modify (if needed) those data sources.
👍 1
z

zhuinden

05/16/2022, 10:59 AM
Repository is just the new name for "Manager" in the Android world, so they can do literally anything and everything
l

Lilly

05/16/2022, 9:17 PM
According to Martin Fowler a repository is characterized by an entity container to cache your obtained entities. Also one repository class only handles one entity, e.g. FirmwareRepository obtains only "FirmwareModel"s. There is no other use case for it
2
5 Views