I have only one class with many instances. Every instance is observer of couple of other instances. As well every instance can be observable by couple of another instances.
How to avoid infinite loop of calling update() in observers?
If your system is single threaded, then you simply need a guard inside your notify method:
private boolean _notifying;
public void notify() {
if(_notifying) {
return;
}
_notifying = true;
try {
// ... do notifying here...
} finally {
_notifying = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With