Endre Deak
09/24/2021, 8:50 PM// delegation as of now:
interface A { fun foo() }
interface B { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B, A by a { override fun bar() = println("bar") }
// delegation after proposal:
interface A { fun foo() }
interface B : A { fun bar() }
class AImpl() : A { override fun foo() = println("default foo") }
class BImpl(private val a: AImpl) : B by a { override fun bar() = println("bar") }
Hope this makes sense. The benefit is that BImpl
does not have to explicitly rely on interface A
.uli
09/24/2021, 9:23 PMclass BImpl(private val a: A) : A by a, B { override fun bar() = println("bar") }
Endre Deak
09/24/2021, 9:47 PMA
at BImpl
.uli
09/24/2021, 9:52 PMEndre Deak
09/24/2021, 9:54 PMBImpl
rather than B
.Endre Deak
09/24/2021, 9:54 PMA
via AImpl
)Endre Deak
09/24/2021, 9:55 PMEndre Deak
09/24/2021, 9:57 PM// this works
interface A { fun foo() }
interface B { fun bar() }
class Mixed : A, B {
override fun foo() {}
override fun bar() {}
}
// this works as well
interface A { fun foo() }
interface B : A { fun bar() }
class Mixed : B {
override fun foo() {}
override fun bar() {}
}
// this also works
interface A { fun foo() }
interface B { fun bar() }
class Mixed(val a: AImpl) : B, A by a {
override fun bar() {}
}
// now I don't see a reason why this should not work
interface A { fun foo() }
interface B : A { fun bar() }
class Mixed(val a: AImpl) : B by a {
override fun bar() {} // I still need to implement methods defined in interface B
}
uli
09/24/2021, 10:02 PMuli
09/24/2021, 10:03 PMfun foo(), inherited from A
Endre Deak
09/24/2021, 10:06 PMinterface A { fun foo() }
interface B : A { fun bar() }
class Mixed(val a: AImpl) : B {
override fun foo() { a.foo() }
override fun bar() {}
}
Endre Deak
09/24/2021, 10:07 PMEndre Deak
09/24/2021, 10:10 PMinterface A { fun foo() }
interface B : A { fun bar() }
class Mixed(val a: AImpl) : B, A by a { // via B, A is already part of the interface definition, why I need to write it down again?
override fun bar() {}
}
Ruckus
09/27/2021, 2:50 PMwhy I need to write it down again?Because you're specifically delegating the implementation of
A
, not B
.