Last active
June 10, 2019 11:59
-
-
Save markmaynard/d27a4b8b359c5ad3abede8121f8b6a92 to your computer and use it in GitHub Desktop.
Sealed class for factory
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
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