YogenGhodke
8/31/2019 - 6:22 PM

Example of Interface Delegation

package Aquarium

interface FishColor
{
    val color: String
}

interface FishAction
{
    fun eat()
}

object GoldColor : FishColor
    {
        override val color = "Gold"
    }

class Shark : FishAction, FishColor by GoldColor            // Uses values from GoldColor
{
    override fun eat()
        {
            println("Eat Algae")
        }
        
    override val color: String = "gold"
}

fun delegate()
{
    val s = Shark()         // Object of class Shark
    println(s.color)
    s.eat()
}


fun main()
{
    delegate()
}