October 2018
Intermediate to advanced
370 pages
9h 15m
English
The Observer pattern allows an object to determine the state change of another object. An instance that is interested can subscribe and immediately be notified when the value of a certain field is changed. The following diagram shows this case:

The preceding diagram contains the TextChangeListener interface, which is implemented by the Observer class. The TextInput class contains a reference of the TextChangeListener type. Whenever the text property of an instance of the TextInput class is changed, the onTextChange method is invoked.
The following snippet demonstrates how this pattern can be implemented:
typealias TextChangeListener ...
Read now
Unlock full access