July 2018
Intermediate to advanced
242 pages
8h 6m
English
We have defined the ObservableVetoable class and delegated the var temperature: Int variable to the ObservableVetoable instance. Our ObservableVetoable class extends the ObservableProperty class, which implements the ReadWriteProperty interface under the hood. Thanks to this, ObservableProperty allows us to delegate mutable properties to it. The ObservableProperty class also has the beforeChange(): Boolean and afterChange(): Unit open functions, which are being invoked inside the setValue() function:
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { val oldValue = this.value if (!beforeChange(property, oldValue, value)) { return } this.value = value afterChange(property, oldValue, value)}
Read now
Unlock full access