Delegating to a Parameter
Explore how Kotlin's delegation feature can be enhanced by delegating to constructor parameters instead of implicit instances. Understand how this approach allows flexible delegation to different implementations, access to delegate properties, and improved design in your Kotlin classes.
We'll cover the following...
We'll cover the following...
The problem
In the previous example, we wrote Worker by JavaProgrammer(), which says that the Manager instance is delegating to an implicitly created instance of the JavaProgrammer, but that poses two issues. First, the instances of Manager class can only route to instances of JavaProgrammer, not to instances of any other Worker implementors. Second, an instance of Manager doesn’t have access to ...