Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created February 15, 2019 05:58
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 theapache64/5a021e4de5a01019962ff191ee121cd7 to your computer and use it in GitHub Desktop.
Save theapache64/5a021e4de5a01019962ff191ee121cd7 to your computer and use it in GitHub Desktop.
Delegation Pattern `by` Kotlin
interface Car {
fun carMethod();
}
interface Bus {
fun busMethod();
}
class Leyland : Bus {
override fun busMethod() {
println("Bus method")
}
}
class BMW : Car {
override fun carMethod() {
println("Car method")
}
}
class Combination(c: Car, b: Bus) : Car by c, Bus by b
fun main(args: Array<String>) {
val busPlusCar = Combination(BMW(), Leyland())
busPlusCar.busMethod()
busPlusCar.carMethod()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment