Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we create a separate repository for each Activity or single repository for entire app

I am following MVVM architecture for my app. In Activity I need to getNews() from a URL, if news is not already cached.

Activity will ask ViewModel to give the News Json and ViewModel will look into the repository, and decide to send data from local or remote repository.

Now the confusion stems from the following point: Should I create a separate Repository class for each Activity, or a general Repository class for the entire project with which each activity communicates. The repository class would be huge in the second approach.

I am unable to find out any official guideline on this topic, and I would like to know the best practice on this regard.

like image 570
dev90 Avatar asked May 22 '18 11:05

dev90


1 Answers

Creating a single repository for the whole app is definitely not a good idea, since that will become very large and completely unmanagable very fast.

I would suggest that you create separate repositories for every viewmodel and additionally services for data that is used by multiple viewmodels.

In your example that would mean that you have a NewsSource service that takes care of retrieving and caching the news JSON and have all your repositories that need that data retrieve it from there.

like image 141
Bmuig Avatar answered Oct 15 '22 18:10

Bmuig