samedi 28 juillet 2018

How to avoid a Circular Dependency

I have a class, let's call it A, which holds an array of a different class, called B. Each B class has a reference to the A class which holds it.

Let's assume each B is a button, and upon clicking I want to print to the number of "brothers" buttons this buttons has.

The way I do it now, is simply going to the A class via a saved reference in B and returning it's array size.

I think my design is poor since both classes, A and B, are aware of each other. What would be a better way of designing such a structure?

Thank you.

Aucun commentaire:

Enregistrer un commentaire