-
-
Save le0nidas/d4e9b7d775e9e984cab3bbc624616203 to your computer and use it in GitHub Desktop.
This file contains 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 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