Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to do delegation in Kotlin

How to do delegation in Kotlin

5 minute talk about delegation in Kotlin programming language.

Harri Kirik

February 05, 2018
Tweet

More Decks by Harri Kirik

Other Decks in Programming

Transcript

  1. KOTLIN: DELEGATION class CarBody { int getDoorCount() { return 4;

    } } class Car { CarBody body; public Car(CarBody body) { this.body = body; } public int getDoorCount() { return body.getDoorCount(); } } #demoday
  2. KOTLIN: DELEGATION interface CarBody { fun getDoorCount(): Int } class

    CarBodyImpl() : CarBody { override fun getDoorCount() = 4 } class Car(c: CarBody) : CarBody by c #demoday
  3. KOTLIN: DELEGATION interface CarBody { fun getDoorCount(): Int } class

    CarBodyImpl() : CarBody { override fun getDoorCount() = 4 } class Car(c: CarBody) : CarBody by c #demoday
  4. KOTLIN: DELEGATION interface CarBody { fun getDoorCount(): Int } class

    CarBodyImpl() : CarBody { override fun getDoorCount() = 4 } class Car(c: CarBody) : CarBody by c #demoday
  5. KOTLIN: DELEGATION interface CarBody { fun getDoorCount(): Int } class

    CarBodyImpl() : CarBody { override fun getDoorCount() = 4 } class Car(c: CarBody) : CarBody by c fun main(args: Array<String>) { val car = Car(CarBodyImpl()).getDoorCount() println(car) } #demoday