Factoring common code as another sub-module

Another solution is to split the dependent member into a separate sub-module and have both existing modules depend on the new sub-module.

Suppose that we have two sub-modules set up in a way that they use functions from each other. Consider the scenario depicted in the diagram as follows:

The func1 function from the first sub-module uses func6 from the other sub-module. And, the func4 function from the other sub-module needs to call the func3 function from the first module. Clearly, there is a high coupling between these two modules.

Considering the dependencies between these modules, it looks like a cycle as the first sub-module depends on the second sub-module and vice versa. To fix that, we can introduce a new sub-module to break the cycle as follows:

Breaking the cycle has the benefit of a cleaner dependency graph. It also makes the code easier to understand.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.151