https://kotlinlang.org logo
n

Nuru

11/16/2020, 9:46 AM
Have gone through the official docs and some tutorials online but still quite unsure where and when to use Interface Delegation. When do you use Interface Delegation in your projects? 🤔 Examples and instances would be greatly appreciated. 🙏🏾
n

Nikky

11/16/2020, 10:02 AM
i use it when i want to compose classes of multiple objects ie common and specifics
Copy code
data class ComposedComponent(
   val common: Common,
   val specific: SpecificComponent
): ICommon by common, ISpecific by specific
it saves typing and making copypaste errors sadly it does not flatten it magically inside serialization
r

Rob Elliot

11/16/2020, 10:29 AM
u

ursus

11/17/2020, 12:50 PM
Use inheritance when you will reference the interface (List, MutableList etc). Else use composition
3 Views