mercredi 21 avril 2021

Is two way classes association bad?

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?

Aucun commentaire:

Enregistrer un commentaire