Last active
August 10, 2020 16:32
-
-
Save catalinghita8/c9b9fc71e4a671315ffb08355511c9ea to your computer and use it in GitHub Desktop.
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 DataSource { | |
| fun getData(): String | |
| } | |
| class LocalDataClient: DataSource { | |
| override fun getData() = sharedPreferences.getString(KEY) | |
| } | |
| class RemoteDataClient: DataSource { | |
| override fun getData() = retrofit.getValue(KEY) | |
| } | |
| class DataViewModel(private val dataClient: DataSource) { | |
| fun getCachedData() = dataClient.getData() | |
| } | |
| // Container of objects shared across the whole project | |
| class DependencyInjector { | |
| val localDataClient: DataSource = LocalDataClient() | |
| val remoteDataClient: DataSource = RemoteDataClient() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment