Observable

open class Observable<T> : ObservableIfc<T>

The Java observer/observable pattern has a number of flaws. This class provides a base implementation of the observer/observable pattern that mitigates those flaws. This allows observers to be added and called in the order added to the component. The basic usage of this class is to have a class have an instance of Observable while implementing the ObservableIfc. The notifyObservers() method can be used to notify attached observers whenever necessary.

Author

rossetti

Inheritors

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun attachObserver(observer: ObserverIfc<T>)

Allows the adding (attaching) of an observer to the observable

Link copied to clipboard
open override fun countObservers(): Int

Returns how many observers are currently attached to the observable

Link copied to clipboard
open override fun detachAllObservers()

Detaches all the observers from the observable

Link copied to clipboard
open override fun detachObserver(observer: ObserverIfc<T>)

Allows the deletion (removing) of an observer from the observable

Link copied to clipboard
open override fun isAttached(observer: ObserverIfc<T>): Boolean

Returns true if the observer is already attached

Link copied to clipboard
fun <T> Observable<T>.observe(block: (T?) -> Unit)