In this chapter, we described class delegates, property delegates, and how they can be used to remove redundancy in code. We defined a delegate as an object to which calls from other objects or properties are delegated. We learned design patterns that class delegation is strongly connected to: the Delegate pattern and the Decorator pattern.
The delegation pattern was mentioned as an alternative to inheritance, and the Decorator pattern is a way to add functionality to different kinds of classes that implements the same interface.
We've seen how property delegation works, the Kotlin standard library property delegatesĀ notNull, lazy, observable, andĀ vetoable, and the use of Map as a delegate. We learned how they work and when they should be used. We've also seen how to make a custom property delegate, together with examples of real-life usage.
Knowledge...