June 2018
Intermediate to advanced
310 pages
6h 32m
English
We'll start a bit differently this time. Instead of composing our solution piece by piece, we'll look at the complete solution and decompose it. The code here will help you understand why:
class HappyMap<K, V>(private val map: MutableMap<K, V> = mutableMapOf()) : MutableMap<K, V> by map { override fun put(key: K, value: V): V? { return map.put(key, value).apply { this?.let { println("Yay! $key") } } }}
The hardest part here is to understand the signature. What we need in the Decorator pattern is:
Since we need ...
Read now
Unlock full access