Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active August 10, 2020 16:17
Show Gist options
  • Select an option

  • Save catalinghita8/965f86d915097b12343c4c779c724eef to your computer and use it in GitHub Desktop.

Select an option

Save catalinghita8/965f86d915097b12343c4c779c724eef to your computer and use it in GitHub Desktop.
interface DataSource {
fun getCachedData(): String
}
class LocalDataClient: DataSource {
private val jsonFile = resources.getFile(JSON_FILE_TAG)
override fun getCachedData() = jsonFile.toString()
}
class DataViewModel(private val dataClient: DataSource) {
fun getCachedData() = dataClient.getCachedData()
}
// Container of objects shared across the whole project
class DependencyInjector {
val localDataClient: DataSource = LocalDataClient()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment