Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Last active April 26, 2020 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/d4e9b7d775e9e984cab3bbc624616203 to your computer and use it in GitHub Desktop.
Save le0nidas/d4e9b7d775e9e984cab3bbc624616203 to your computer and use it in GitHub Desktop.
interface Storage {
fun save(workout: Workout)
}
class LocalStorage : Storage {
override fun save(workout: Workout) {
// it saves in our database
}
}
class CloudStorage : Storage {
override fun save(workout: Workout) {
// it saves in someone else's database
}
}
object NullStorage : Storage {
override fun save(workout: Workout) {
// it does nothing
}
}
fun getStorage(type: String): Storage {
return when (type) {
"local" -> LocalStorage()
"cloud " -> CloudStorage()
else -> NullStorage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment