Skip to content

Instantly share code, notes, and snippets.

@markmaynard
Last active June 10, 2019 11:59
Show Gist options
  • Save markmaynard/d27a4b8b359c5ad3abede8121f8b6a92 to your computer and use it in GitHub Desktop.
Save markmaynard/d27a4b8b359c5ad3abede8121f8b6a92 to your computer and use it in GitHub Desktop.
Sealed class for factory
sealed class SomeThing {
abstract fun run()
abstract fun play()
}
class Thing1: SomeThing() {
override fun run() = println("Run Fast!")
override fun play() = println("Play Hard!")
}
class Thing2: SomeThing() {
override fun run() = println("Run Silly!")
override fun play() = println("Play Soft!")
}
class NoThing {} // not part of the sealed class eh? no instantiation for you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment