Hi all.
Alright in my project I followed an offline first architecture where I'm always Querying the local datastore. For each ressources that requires query, a Presenter has two UseCaseobjects:
rx.Subscriber only does Logging. All saving operations are performed in doOnNext. final FetchArticleCollectionUseCase mFetchArticleCollectionUseCase;
final GetArticleUpdatesUseCase mGetArticleUpdatesUseCase;
It's working pretty well now. But I'm wondering if I'm still making a good use of UseCase. And I personally find it cumbersome to write two UseCase for one data output every time.
You shouldn't write Use Cases for this. Use cases are meant for Business logic (what does your app actually do?). This kind of functionality belongs in the Data Layer, as this functionality is about "where do i get my data from". A Use Case doesn't care where the data comes from.
In the case of the Repository pattern, it is the Repository that decides where the data comes from. So a Use case would query the Repository for data, and the Repository goes to check if a local copy is available and pass that. It not, it first gets data from the network, stores it locally and passes it on. This is all it does.
Cache validation (how long is your local data correct?) is the responsibility of the Data Store. There you define how long your data is valid. The Repository would ask the local Data Store if the data is there and if it is valid and then act on it. If it is valid, just return what the local Data Store has. Otherwise the Repository creates a Network Data Store and uses that to get the data and save it to the local Data store.
Most helpful comment
You shouldn't write Use Cases for this. Use cases are meant for Business logic (what does your app actually do?). This kind of functionality belongs in the Data Layer, as this functionality is about "where do i get my data from". A Use Case doesn't care where the data comes from.
In the case of the Repository pattern, it is the Repository that decides where the data comes from. So a Use case would query the Repository for data, and the Repository goes to check if a local copy is available and pass that. It not, it first gets data from the network, stores it locally and passes it on. This is all it does.
Cache validation (how long is your local data correct?) is the responsibility of the Data Store. There you define how long your data is valid. The Repository would ask the local Data Store if the data is there and if it is valid and then act on it. If it is valid, just return what the local Data Store has. Otherwise the Repository creates a Network Data Store and uses that to get the data and save it to the local Data store.