janishar / android-mvp-interactor-architecture

Extension of the android-mvp-architecture for very large projects.
Apache License 2.0
405 stars 97 forks source link

Why not using separate datasource(Local-DB, Cloud-API) in the reposiotry? #8

Open souravpalitrana opened 6 years ago

souravpalitrana commented 6 years ago

Here repository is the bridge to get data from Database. It has no other data source. So if you want to use data cache what will you do? In that case, it will be better if repository may have two data sources. One is local data store and another is cloud data store or you can use a data store factory to create a data source for the repository. I am telling that because it is a standard boilerplate. If you add that then it will help others in that scenario.

I want to know your opinion.

janishar commented 6 years ago

The Interactor is designed to be use specific.

If an Interator need data from disc/ memory cache then we can create a DiscCacheHelper/MemCacheHelper and provide this helper to that Interactor just like Repositories.

Repositories only deals with methods for the data in the database.

For cloud data we have ApiHelper.

You are right we could possibly segregate Repository into LocalRepository and RemoteRepository but since for RemoteRepository we have used ApiHelper so we assume that a Repository to be LocalRepository.

If we have a very large number of API endpoints and we think to modularize ApiHelper then we can replace ApiHelper with RemoteRepository. But that may be an overkill for most of the apps.

souravpalitrana commented 6 years ago

@janishar So in that case, you have to introduce DiscCacheHelper and your interactor need to decide from where it will pull the data. But I am suggesting that as you are already using repository then your repo can handle that.

A repository will ensure us that the interactor will get the data. Interactor should not know about data abstraction (Local, Cloud, Test). Again in that case interactor will be less complex as it doesn't need to handle all the helper class.

Again if you want to use another helper you have to add that in all interactor.

IomarSantos commented 6 years ago

What would be the strategy for saving local or remote data using LocalRepository RemoteRepository would have to inject the two into Interactor?

souravpalitrana commented 6 years ago

@IomarSantos You should not inject localRepository and remoteRepository both. You should inject a repository. A repository should handle from where it will provide data. However, the repository can use a DataStoreFactory which will provide local or cloud data source based on logic.

Drjacky commented 6 years ago

@souravpalitrana I agree totally with you on Repository design pattern subject, that I think not correctly observed in this example.

And by the way, It would be nice if you could fork this example and implement that :pray:

janishar commented 6 years ago

@souravpalitrana I think there is a confusion. This repository is not analogous to the Repository pattern as the abstraction layer for the data from any source as the android architectural components describe. In this example, the repository is the concept used in database abstraction like in hibernate. Refer to this: https://thinkinginobjects.com/2012/08/26/dont-use-dao-use-repository/

Drjacky commented 6 years ago

@janishar In related to your last comment, so maybe it's better to change the name of Repository to something else; To prevent its similarity to Repository Pattern. :pray:

janishar commented 6 years ago

@Drjacky Okay! I will try to find a less confusing name.