My question will be more design or architecture related. Just need some advice from more experienced engineers.
I'm learning RxJava/RxAndroid now and would like to replace my asynchronous logic in an app based on lessons learned.
I have an app based on MVP pattern and almost every Presenter communicates with Repository. To avoid ANRs I use some async logic inside a Repository class (it is actually not critical what mechanism is exactly used: ThreadPoolExecutor, AsyncTask or JobScheduler).
So I decided to replace that async logic with a set of RxJava classes, but I faced with one interesting question. Where should I implement that async logic from the architectural point of view?
IMHO, there are two possible options (may be there are others):
- Rewrite every Repository and replace all custom async logic with new Reactive one;
- Remove all async logic from Repository (make a class fully synchronous) and move it to some external entity (lets name it "RepositoryAsyncRunner").
If I follow Case #1, then there is a need to change interfaces for every repository and it will work at the same way. Looks like as unnecessary change, because logic has not changed. The only thing has changed is the way of async execution.
If I follow Case #2, then my Presenter will communicate with that async wrapper instead of a plain Repository and all async logic will be encapsulated in a separate class.
Frankly speaking I like the second approach. If I'll change my mind later and want to replace RxJava with another cool library, I have to change only AsyncRunner without modification of Repository class, its interface and related Unit Tests (may be even Presenter's tests won't be changed). Also using this approach I will have two different classes for two different purposes ('S' in SOLID :)
Will be glad to get some help to resolve this situation.