What is Delegation Interface in Kotlin?
Simple explanation of delegation interface in Kotlin with some examples
2 min readFeb 3, 2023
You may be familiar with delegated properties in Kotlin, but have you heard of delegation interface? This is one of the features other programming languages do NOT have.
Standard Interface Implementation
Let’s say you have 2 interfaces below — Interface1
and Interface2
.
interface Interface1 {
fun fun1()
}
interface Interface2 {
fun fun2()
}
You have a Class
that implements these 2 interfaces. So it overrides the fun1()
and fun2()
from these 2 interfaces.
class Class : Interface1, Interface2{
override fun fun1() {
println("fun1")
}
override fun fun2() {
println("fun2")
}
}
In short, the class diagram looks like this.
The caller usage looks like this.
fun main() {
val obj = Class()
obj.fun1()
obj.fun2()
}
There is nothing fancy here, it is a pretty standard interface implementation.