Kotlin takes design patterns pretty seriously. Previously, we've seen how the usage of the Singleton pattern can be simplified using object declarations, and how usage of the Observator pattern can be trivialized using higher-order functions and functional types. Kotlin also simplifies the usage of most functional patterns, thanks to lambda expressions and functional types. In this chapter, we will see how the use of the Delegation and Decorator patterns can be simplified thanks to class delegation. We will also look at a feature that is pretty new in the programming world--property delegation--and how it is used to make Kotlin properties much more powerful.
In this chapter, we will cover the following topics:
- The Delegation pattern
- Class delegation
- The Decorator pattern
- Property delegation
- Property delegates from the standard library
- The creation of a custom property delegate