I have a class below that updates a data variable. How can I observe when this variable changes?
object Manager {
private var data: Type = B()
fun doWork{
while(active) {
if(conditionA)
data = A()
else if(conditionB)
data = B()
}
}
fun getData(): Flow<Type>
}
interface Type {
}
Some classes that implements the interface.
class A: Type {}
class B: Type {}
I want to be able to observe these changes without using LiveData or anything that is Experimental. How can I let other areas of my code observe the data variable?
I know there is BroadcastChannel but I cannot use it because it is experimental.
You can use listener and built-in Kotlin delegate: