Class delegation
Kotlin has a feature called class delegation. It is a really inconspicuous feature that has many practical applications. It is worth noticing, that it is strongly connected with two design patterns: the Delegation pattern and the Decorator patterns. We will discuss those patterns in more detail in upcoming sections. Delegation and Decorator pattern have been around for many years, but in Java their implementation required a lot of boilerplate code. Kotlin was one of the first languages to provide native support for those patterns, reducing boilerplate code to a minimum.
The Delegation pattern
In object-oriented programming, the Delegation pattern is a design pattern that is an alternative to inheritance. Delegation means that the object handles a request by delegating it to another object (delegate), instead of extending the class.
To support the polymorphic behavior known from Java, both objects should implement the same interface which holds all the delegated methods and...