Circular dependency?

if I have two modules A and B, where A needs using B and B needs using A.
would it cause problem? if there is, how could I solve it? thanks. :pray:

1 Like

Unite into single module or move common functionality in a third module C. A circular dependency should more often than not viewed as a design flaw more than an issue to be handled explicitly.

5 Likes

that means there’s no shortcut except to figure out the sequence of module dependencies :slightly_frowning_face:

A different perspective is that it’s a very good opportunity to refactor the code to a better design so you can maintain it more easily going forward.

3 Likes

a. Yes.
b. Depends on preference and how closely related the purposes are of A and B. One strong option is what @zgornel and @tk3369 said. Personally, if I had two interdependent modules, I’d place their common code in one module (let’s call it C), then move the unique parts of A and B to two submodules, C.A and C.B. Then I could play around with import/export/using until the project is clean enough that others can easily follow my steps.

2 Likes