Wrapping Up
Good design guidelines often recommend that we should prefer delegation over inheritance. Yet that was a hard sell in many OO languages, due to lack of direct support for delegation. Kotlin fixes that by providing facilities to delegate calls on objects, and access to both local variables and properties. Using the by keyword, you may delegate reads to any object that implements a getValue() method and writes to any object with setValue() method. Using these low-ceremony facilities, you may create your own custom delegates easily. You can also benefit from a few built-in standard delegates in the Kotlin standard library, like the Lazy delegate for example.
Being a multiparadigm language, Kotlin not only offers extensive OO programming ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access