1
1
Fork 0

Minor: wording improvements

This commit is contained in:
Svetlana Isakova 2020-09-26 21:43:01 +02:00
parent 75d281ac02
commit 2cf5ba2cd9
5 changed files with 17 additions and 16 deletions

View File

@ -10,7 +10,7 @@ class ButtonImage(
val width: Int,
val height: Int
): Rectangle {
override fun paint() =
override fun paint() =
"painting ButtonImage($width, $height)"
}

View File

@ -1,15 +1,15 @@
## Class Delegation (#2)
Exercise 1 in [Inheritance & Extensions] uses
composition to adapt `Crocodile` to work with `interactWithDuck`.
This produces an inconsistency when using `IAmHonestlyDuck` with the
`interactWithCrocodile()` function: the composed `crocodile` must be explicitly
named during the call:
composition to adapt `Crocodile` to work with `interactWithDuck()`. This
produces an inconsistency when using `IAmHonestlyDuck` with the
`interactWithCrocodile()` function---the composed `crocodile` must be
explicitly named during the call:
```kotlin
interactWithCrocodile(honestlyDuck.crocodile)
```
Modify the solution to that exercise using class delegation so you can call a
function `interactWithCrocodile(honestlyDuck)`. Make the `crocodile` argument to
`IAmHonestlyDuck` `private` so you *cannot* expose `field`.
function `interactWithCrocodile(honestlyDuck)`. Make the `IAmHonestlyDuck`
`crocodile` parameter `private` so you *cannot* expose `field`.

View File

@ -1,10 +1,11 @@
## Class Delegation (#3)
What happens when you delegate to two interfaces that have one or more
members in common? The started code contains two interfaces `A` and `B`
that both have `foo()` member function.
members in common? The starter code contains two interfaces `A` and `B`
that both have a `foo()` member function.
Create a class `AImpl` that implements `A`, that traces `"A.foo()"` for `foo()`
and `"A.bar()"` for `bar()`. Create a similar implementation `BImpl`
implementing `B`. Now create a class `Delegation` which delegates to both `A`
and `B`. IntelliJ or the compiler will guide you in resolving the collisions.
Create a class `AImpl` that implements `A` and traces `"A.foo()"` for `foo()`
and `"A.bar()"` for `bar()`. Create a similar implementation `BImpl` that
implements `B`. Now create a class `Delegation` that delegates to both `A` and
`B`. IntelliJ or the compiler will guide you in resolving the resulting
issues.

View File

@ -5,4 +5,4 @@ assume they're part of the third-party library). Implement the `mimicDuck()`
function that dynamically adapts an object, accepting a `Crocodile` and
returning an `IAmHonestlyDuck`. `IAmHonestlyDuck` should implement `Duck` and
delegate both `Duck` member functions to `crocodile.bite()`. Is it possible to
use the inheritance approach, or are you forced to use composition?
use inheritance, or are you forced to use composition?

View File

@ -12,8 +12,8 @@ fun main() {
capture {
testFortyTwo2(43)
} contains
listOf("expected:", "<43> " +
"but was:", "<42>")
listOf("expected:",
"<43> but was:", "<42>")
assertFails { testFortyTwo2(43) }
capture {
assertFails { testFortyTwo2() }