Spot problems with circular dependency
Solution 1:
The clean way to handle this is using dependency injection, to keep the dependencies at the interface level.
It's ok for UserMain
to depend on FilesInternaService
and it's ok for FileMain
to depend on UserInternalService
; but it's not ok for UserMain
to depend on FileMain
or for FileMain
to depend on UserMain
. In other words, it's not ok to depend on concrete implementation.
An instance of FilesInternaService
should be injected into UserMain
and an instance of UserInternalService
should be injected into FileMain
.
References
- Are circular dependencies considered bad design?
- Why are circular references considered harmful?
- https://softwareengineering.stackexchange.com/questions/11856/whats-wrong-with-circular-references
- https://softwareengineering.stackexchange.com/questions/306483/how-to-solve-circular-dependency