Below is program code, in which the Counter class delegates the implementation of the following Increment interface:
interface Increment {
fun increment()
}
The Increment interface is delegated to the IncrementHandler class:
class IncrementHandler(private val counter: Counter) : Increment {
override fun increment() {
counter.count++
}
}
Your task is to correctly position the lines of code to make the program run.
fun main() {
val counter = Counter(0) { IncrementHandler(it) }
for (i in 1..5) {
counter.increment()
println("Count: ${counter.count}")
}
}