November 2018
Intermediate to advanced
388 pages
9h 5m
English
Now we need to add the decorators to the window. To do this, we will create a WindowDecorator class, which is our decorator. This class implements the following Window component:
class WindowDecorator(private val window: Window) : Window { override fun getDescription(): String { return window.getDescription() } override fun getPrice(): Double { return window.getPrice() }}
This class takes an instance of a Window type in its constructor, and this is the instance that is decorated. We also override the getDescription() and getPrice() functions.
Now let's write a concrete decorator. This is called Arched, which refers to the shape of the window:
class Arched(private val window: Window) : WindowDecorator(window) { internal var ...Read now
Unlock full access