Skip to content

Commit e1e886c

Browse files
committed
update: fix delegation samples in intermediate tour
1 parent 5aff3dc commit e1e886c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/topics/tour/kotlin-tour-intermediate-classes-interfaces.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ interface Drawable {
286286
```
287287

288288
You create a class called `Circle` which implements the `Drawable` interface and provides implementations for all of
289-
its member functions:
289+
its members:
290290

291291
```kotlin
292292
class Circle : Drawable {
@@ -297,6 +297,7 @@ class Circle : Drawable {
297297
override fun resize() {
298298
TODO("An example implementation")
299299
}
300+
override val color = null
300301
}
301302
```
302303

@@ -328,7 +329,7 @@ you can create an instance of the `Circle` class and delegate the implementation
328329
class to this instance. To do this, use the `by` keyword. For example:
329330

330331
```kotlin
331-
class RedCircle(param: Circle) : Circle by param
332+
class RedCircle(param: Circle) : Drawable by param
332333
```
333334

334335
Here, `param` is the name of the instance of the `Circle` class that the implementations of member functions are delegated to.
@@ -340,7 +341,7 @@ you add code only for the behavior you want to change for your child class.
340341
For example, if you want to change the value of the `color` property:
341342

342343
```kotlin
343-
class RedCircle(param : Circle) : Circle by param {
344+
class RedCircle(param : Circle) : Drawable by param {
344345
// No boilerplate code!
345346
override val color = "red"
346347
}
@@ -670,7 +671,7 @@ class BasicMessenger : Messenger {
670671
}
671672
}
672673

673-
class SmartMessenger(private val basicMessenger: BasicMessenger) : Messenger by basicMessenger {
674+
class SmartMessenger(val basicMessenger: BasicMessenger) : Messenger by basicMessenger {
674675
override fun sendMessage(message: String) {
675676
println("Sending a smart message: $message")
676677
basicMessenger.sendMessage("[smart] $message")

0 commit comments

Comments
 (0)