Created
January 8, 2022 21:27
-
-
Save leomayleomay/89dd169b067d37a2f26a0282befac95c to your computer and use it in GitHub Desktop.
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
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