Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SharedPreferences or File on MVVM

I am curious about the role of the repository in the MVVM architecture .If you decide to add repository to your project, will this repository be responsible only for data from database or network ? The question is about SharedPreferences or Files , should I hold the repository responsible for that , or should I keep them in the ViewModel .

like image 732
coroutineDispatcher Avatar asked Apr 25 '19 14:04

coroutineDispatcher


1 Answers

From what I understand in MVVM I can say:

  • Repository should be responsible for all data that your project component ask for. Whether it's from Database or API.

  • Let repository grab all data from Database/API/Server/etc. Then you grab data from that repository.

  • You can have multiple repository if you need, like API Repository/FirebaseRepository/RoomRepository etc...

  • You can merge multiple data sources into one repository, but you need to handle that manually.

like image 72
MohammadL Avatar answered Nov 13 '22 09:11

MohammadL