Skip to content

Instantly share code, notes, and snippets.

@hugoangeles0810
Created January 15, 2018 01:09
Show Gist options
  • Select an option

  • Save hugoangeles0810/8580dc577ba4d26821cc491b20db55d8 to your computer and use it in GitHub Desktop.

Select an option

Save hugoangeles0810/8580dc577ba4d26821cc491b20db55d8 to your computer and use it in GitHub Desktop.
Inversión de dependencias - Ejemplo
interface LocalDataSource {
fun saveOrUpdateColors(colors: List<Color>)
fun listColors(): List<Color>
}
interface RemoteDataSource {
fun listColor(): List<Color>
}
class RestDataSource : RemoteDataSource {
override fun listColor(): List<Color> {
TODO("Implementation code here")
}
}
class SQLiteDataSource : LocalDataSource {
override fun saveOrUpdateColors(color: List<Color>) {
TODO("Implementation code here")
}
override fun listColors(): List<Color> {
TODO("Implementation code here")
}
}
class ColorsRepository(val remoteDataSource: RemoteDataSource, val localDataSource: LocalDataSource) {
fun listColors(): List<Color> {
val colors = remoteDataSource.listColor()
localDataSource.saveOrUpdateColors(colors)
return colors
}
fun listLocalColors(): List<Color> {
return localDataSource.listColors()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment