Created
January 15, 2018 01:09
-
-
Save hugoangeles0810/8580dc577ba4d26821cc491b20db55d8 to your computer and use it in GitHub Desktop.
Inversión de dependencias - Ejemplo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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