I'm trying to split a large class into smaller com...
# announcements
b
I'm trying to split a large class into smaller composable classes using class delegation. The smaller classes still need access to a component or function in the main class though. I want to do something like
class SomeClass : ApiX by ApiXImpl(::send)
But the object doesn't exist yet so
::send
doesn't work. Is there a way to accomplish this or do I need to abandon class delegation and just manually wrap all the calls?
g
It seems to be only Kotlin FE limitation. But you can workaround it by creating another class
Copy code
interface Bar {
    fun bar()
}

class BarImpl(val commonData: CommonData): Bar {
    override fun bar() {
        println("Calling bar: ${commonData.value}")
    }
}

class CommonData(val value: Int)

class Foo(val commonData: CommonData): Bar by BarImpl(commonData)

fun main(args: Array<String>) {
    val foo = Foo(CommonData(42))
    foo.bar()
}