Member-only story
Kotlin Delegates
Learn about Different Delegates in Kotlin
Kotlin language is a pack of many awesome features. Once you start using the features of Kotlin you will understand them better. In this post, let's explore Kotlin Delegates and how to use them.
Introduction to Delegation Pattern
In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance — Wikipedia
We can say delegation is an alternative to inheritance however they both provide similar behavior. Both of them allow us to reuse the code but slightly in a different way. In some cases, we need to use delegates instead of inheritance
- Where a class is not designed for inheritance — like when a class is final, private, etc.
- When we only need some functionality from the base class rather than all
But we rarely see the implementation of Delegation as we are habituated with ease of using inheritance or lack of good support.