September 2019
Intermediate to advanced
462 pages
11h 3m
English
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 the delegate; that is, if we were to write a method in the Manager class, we can’t access the delegate from that method. It’s easy to fix those limitations by tying the delegate to the parameter passed to the constructor instead of to an implicitly created instance.
| | class Manager(val staff: Worker) : Worker ... |
Read now
Unlock full access