0

I was developing one tool, and noticed what my classes use "two way association". Objects of class A have a pointer to B, and B have pointer to A. I tried to find out, is that a bad design architecrute, or it is ok, but didn't found anything.

class A {
    B field;
    
    public A(B field) {
      this.field = field;
    }
}

class B {
    A field;
    
    public B() {
      field = new A(this);
    }
}

So, how bad this is?

MadL1me
  • 31
  • 7
  • 2
    Yes, [circular references are bad](https://softwareengineering.stackexchange.com/a/12030/19115). – Mark Seemann Apr 21 '21 at 11:47
  • @MarkSeemann, your coauthor seems to disagree, in [Why are circular references considered harmful?](https://stackoverflow.com/questions/1897537/why-are-circular-references-considered-harmful) – jaco0646 Apr 21 '21 at 13:54
  • @jaco0646 While that sometimes happens, that's not the case here. My co-author is [Steven](https://stackoverflow.com/users/264697/steven), not [Stephen C](https://stackoverflow.com/users/139985/stephen-c) – Mark Seemann Apr 21 '21 at 14:47
  • @MarkSeemann, my apologies. I was close on the name! :) – jaco0646 Apr 21 '21 at 15:14

0 Answers0