Kotlin has class and property delegation. I wonder...
# language-evolution
a
Kotlin has class and property delegation. I wonder if it makes sense to also have function delegation. For example, imagine a Facade that for some functions, simply delegates it’s exposed public function to something else:
Copy code
class Facade(
   private val delegate:Delegate
) {
    fun aaa(a,b,c,d) by delegate::bbb
}

class Delegate {
   fun bbb(a,b,c,d) { ... }
}
If the number of arguments or functions increases, doing it manually like
fun aaa(a,b,c,d,e,f) = delegate.bbb(a,b,c,d,e,f)
becomes tedious. This seems useful if a class needs to delegate to another class, only a subset of some interface, or does not want to implement the whole interface via class delegation.
4
c
Additional use-case: having this would very highly reduce the need for stubbing and mocking frameworks.
Copy code
interface System {
    fun x()
    fun y(): String
}

class MockedSystem(
    private val mockLogic: MockLogic,
) {
    override fun x() by mockLogic::mock
    override fun y() by mockLogic::mock
}
where
MockLogic
could implement centrally the logic for stubbing etc.
p
Isn't this likely to get messy with conflicting overloads/default parameters?
c
How would it get messy? Each function would be delegated to another one with the exact same signature (so in my example
MockLogic.mock
needs to have overloads for all possible signatures, but that's fine)