How to manage repository pattern when you have off...
# android
p
How to manage repository pattern when you have offline and online repositories? First I developed the online repository which gets a complex busstop instance, parsed with retrofit converters:
Copy code
interface BusDataRepository {
    suspend fun getBusStops(): ComplexBusStopGroup
}
class NetworkBusDataRepository(
    private val retrofitService: BusDataApiService
) : BusDataRepository {
    override suspend fun getBusStops(): ComplexBusStopGroup = retrofitService.getBusStops()
}
Then I added a offline repository for caching and retrieving the data from offline database, but then I noticed that the database table is not a
ComplexBusStopGroup
but a simple list of BusStop instances, which is different. Then, my next code doesn't work, because the return type Flow<ListBusStop> is not the same as the original interface return type:
Copy code
class OfflineBusDataRepository(
    private val BusStopsDao: BusStopsDao
) : BusDataRepository {
    override suspend fun getBusStops(): Flow<List<BusStop>> = BusStopsDao.getAllBusStops()
How is this issue managed in pattern repository with offline and online datasources?
not kotlin but kotlin colored 1
a
Normally you use a single repository with remote and local source. But you can also use a mediator.