Skip to content

Instantly share code, notes, and snippets.

@leomayleomay
Created January 8, 2022 21:27
Show Gist options
  • Save leomayleomay/89dd169b067d37a2f26a0282befac95c to your computer and use it in GitHub Desktop.
Save leomayleomay/89dd169b067d37a2f26a0282befac95c to your computer and use it in GitHub Desktop.
interface Vehicle {
fun go(): String
}
class CarImpl(val where: String): Vehicle {
override fun go() = "is going to $where"
}
class AirplaneImpl(val where: String): Vehicle {
override fun go() = "is flying to $where"
}
class CarOrAirplane(
val model: String,
impl: Vehicle
): Vehicle by impl {
fun tellMeYourTrip() {
println("$model ${go()}")
}
}
fun main(args: Array<String>) {
val myAirbus330
= CarOrAirplane("Lamborghini", CarImpl("Seoul"))
val myBoeing337
= CarOrAirplane("Boeing 337", AirplaneImpl("Seoul"))
myAirbus330.tellMeYourTrip()
myBoeing337.tellMeYourTrip()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment