Search code examples
design-patternsobservers

Is this called "Circular Reference"?


Having the Observer pattern, we all know that based on its class diagram, the SUBJECT uses a reference to the OBSERVER. Meanwhile, the OBSERVER has a reference to SUBJECT in order to register or remove itself.

Is this a "Circular Reference"?


Solution

  • As you describe it, it is a case of circular reference. However, note that in the full pattern, Observer is an abstract class / interface, which has one or more concrete implementations. Observer in some variations knows nothing about Subject (although its subclasses may refer to it), in other variations it may depend on an Observable interface or directly on Subject. However, Subject knows only about Observer, not its concrete subclasses.

    So the reference is not (necessarily) circular.