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.<
Well, if you are defining the "event" object, you could maybe add to it the objects that have processed the event already. In that case, if you close the loop you can exit. In seudo-code
eventFired(Event e)
if (e.hasBeenEvaluatedBy(this)){
return;
}
e.addEvaluator(this);
// Do magic
refire(e);
}
In this case we get something like: * A fires something. * B processes it and adds itself to the list * B refires * C processes event and adds itself to the list * C refires * A processes the event and adds itself to the list * A refires * B catches the event, but is already on the list. No refire, infinite loop broken
Ids could be used instead of pointers to avoid garbage collection issues