PHondogo
12/21/2022, 7:30 AMinterface IFace {
fun test()
fun test2()
// etc...
}
class A : IFace {
override test() {}
override test2() {}
// etc...
}
class B : IFace {
private val a = A() // Is it possible to specify that B must delegate all IFace functions to a without passing a in constructor?
}
Stephan Schröder
12/21/2022, 8:35 AMFace
. Ideally you can also avoid calling the implementation FaceImpl
, but use an implementation detail to name it (e.g. MultiThreadedFace
).Joffrey
12/21/2022, 8:39 AMclass B : IFace by A()
Joffrey
12/21/2022, 8:40 AMA
, you can also pass it in the constructor but with a default value, so that the callers of B's constructor don't have to specify it:
class B(private val a: A = A()) : IFace by a
Stephan Schröder
12/21/2022, 8:43 AMPHondogo
12/21/2022, 8:54 AMJoffrey
12/21/2022, 1:30 PMJoffrey
12/21/2022, 1:31 PMA
from the property and then call the method on that A
PHondogo
12/21/2022, 2:52 PM