Ist das „Circular Reference“ genannt?
-
09-10-2019 - |
Frage
das Beobachter-Muster zu haben, wir alle wissen, dass auf seine Klassendiagramm basiert, verwendet das SUBJECT einen Verweis auf die BEOBACHTER. Inzwischen hat die Beobachter einen Verweis auf SUBJECT, um sich zu registrieren oder zu entfernen.
Ist das eine "Circular Reference"?
Lösung
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.
Andere Tipps
Sure, it's a circular reference. It's a cycle in the graph of references.
Using the term "circular references" sometimes occurs when talking about more harmful things though, particularly when you have circular dependencies (e.g. A needs B to compile, but B needs A to compile).
A circular reference in itself isn't harmful (e.g.: a circular linked list).