please help. I have a project where I need to change data source depends on some conditions.
The problem is, I don't know how to do it by clean-architecture and SOLID way.
I have class for getting data from network data source and class for getting same data from local database. Both of this classes implements one interface, but has some difference in their constructors. Code snipped below:
interface GoodsRepository {...}
class GoodsRepositoryNet(
private val goodsService: GoodsService,
private val deviceModel: DeviceModel) : GoodsRepository {...}
class GoodsRepositoryLocal(
private val goodsService: GoodsServiceDao,
private val deviceModel: DeviceModel) : GoodsRepository {..}
In some view model class I put GoodsRepository interface as an argument to constructor of ViewModel. I'm using Hilt for DI.
So, at first in viewmodel (or where?), I must check if there is a data in the local database, and if not, load data from network.
Where should I do all this things?
In my current release viewModel loads data from some repository.
If I @Inject manually local repository, so program loads data from local DB, but at first start local DB is empty, so I should load data from network.
This is the point where I got stuck: How to change repository with respect of clean-architecture and SOLID-princeples?