Spot problems with circular dependency

后端 未结 1 1176
庸人自扰
庸人自扰 2020-12-12 07:56

I am designing a system where two modules, one which gestions files and another users. For certain logic operations, they need the services offered by each other.

Ea

相关标签:
1条回答
  • 2020-12-12 08:39

    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

    1. Are circular dependencies considered bad design?
    2. Why are circular references considered harmful?
    3. https://softwareengineering.stackexchange.com/questions/11856/whats-wrong-with-circular-references
    4. https://softwareengineering.stackexchange.com/questions/306483/how-to-solve-circular-dependency
    0 讨论(0)
提交回复
热议问题