Are circular dependencies considered bad design?

后端 未结 2 896
不知归路
不知归路 2020-12-17 01:23

In my work (which is 90% Java but I\'m sure this question applies to other languages) I often create two classes that \"know about\" each other. More concretely, class A im

2条回答
  •  悲&欢浪女
    2020-12-17 02:12

    Here is my take:

    • If the two classes belong to the same logical module, then it's probably fine (still a judgement call of course, with lots of grey areas).
    • It's less fine if the two classes belong to different modules. This creates a circular dependency between modules. I try to avoid that as much as can, preferring a clear hierarchical structure.

提交回复
热议问题