Skip to content

Instantly share code, notes, and snippets.

@detsam
Created December 13, 2016 13:51
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 detsam/1f8b78e83cbbd8357af6ee87733a3320 to your computer and use it in GitHub Desktop.
Save detsam/1f8b78e83cbbd8357af6ee87733a3320 to your computer and use it in GitHub Desktop.
class Platform {
fun install(vararg module: Module) {
module.forEach { mod -> mod.install() }
}
fun Module.install() {
setup()
}
fun Module.modInitialMessage(message:String) {
println(message)
}
}
interface Module {
fun Platform.setup()
}
class TeeModule : Module {
override fun Platform.setup() = modInitialMessage("Installing tee...")
}
class CoffeeModule : Module {
override fun Platform.setup() = modInitialMessage("Installing coffee...")
}
fun main(args: Array<String>) {
TeeModule().install() // <-- Does Not Exist
TeeModule().setup() // <-- Does Not Exist
val platform = Platform()
platform.install() // <--- OK
platform.modInitialMessage() // <--- Does Not Exist
platform.install(
TeeModule(),
CoffeeModule()
)
// ... ->
//
// Installing tee...
// Installing coffee...
//
//
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment