Implementing the advanced Observer pattern by defining a custom property delegate
In this recipe, we are going to implement a custom, generic property delegate combining features of the Observable and Vetoable delegates available in the standard library. In other words, we want to implement a property delegate that allows us to notify a subscribed listener about any changes made to the observed property. At the same time, we also want the delegate to allow filtering of the updates made to the delegated property. In this example, we are going to declare the temperature: Int
variable delegated to our custom implementation of the ObservableVetoable
delegate class. We are going to create a generic class that allows us to pass the initial value, a function responsible for filtering property updates and a function that will be invoked immediately after the change to the property is made.
How to do it...
- Define the custom property delegate called
ObservableVetoableDelegate
as a subclass of theObservableProperty...