June 2018
Intermediate to advanced
310 pages
6h 32m
English
The Decorator design pattern is great because it lets us compose objects on the fly. Using Kotlin's by keyword will make it simple to implement. But there are still limitations that you need to take care of.
First, you cannot see inside of the Decorator:
println(sadHappy is SadMap<*, *>) // True
That's the top wrapper, so no problem there:
println(sadHappy is MutableMap<*, *>) // True
That's the interface we implement, so the compiler knows about it:
println(sadHappy is HappyMap<*, *>) // False
Although SadMap contains HappyMap and may behave like it, it is not a HappyMap! Keep that in mind while performing casts and type checks.
Second, which is related to the first point, is the fact that since Decorator is usually not aware directly ...
Read now
Unlock full access