I am trying to implement two interfaces, using the same delegate for both. So if I want to implement these interfaces:
interface A {
fun foo()
}
interface B {
fun bar()
}
with a delegate from this class
class C: A, B {
override fun foo() {
println("foo!")
}
override fun bar() {
println("bar!")
}
}
to do it using the by keyword, I could try something like this
class D: A by C(), B by C()
but this requires creating two instances of C, which may not be desirable.
Or I could try
class D(c: C = C()): A by c, B by c
which requires changing the constructor. This may also not be desirable.
Is there some way to do this efficiently, or do I have to go with boilerplate and implement A and B in the class body?