According to this answer (and many other articles from other sites), interfaces are the solution to solve circular references, but yet none of it explained "how and why"? (except assembly issues)
Here is what I don't understand:
Say, if we add a constructor to both Foo
and Bar
in the linked answer as follows:
public Foo()
{
myBar = new Bar(this);
}
public Bar(Foo foo)
{
myFoo = foo;
}
Then how is it "not referencing each other", since we can endlessly call myBar.myFoo.myBar.myFoo...
and result in a "closed loop"?
I know I shouldn't "purposely" write constructors that will reference each other, but, in most cases, circular references are created, albeit bad design, because "A class wants to know something about B class and vice versa", so it wouldn't make any sense if someone creates 2 classes that "have nothing to do with each other". If that's the case, then there are no "circular reference issues" to begin with.
So, could somebody please be so kind explaining it to me?