3 ms·
> But you just created a circular dependency! Only if those things not only need to be able to “get to” each other, but also need to know, at compile time, abo
by dragonwriter 5y ago
> But you just created a circular dependency!
Only if those things not only need to be able to “get to” each other, but also need to know, at compile time, about the concrete implementation of the others.
That's possible to be a real need, but its also something that often happens because of excessive and unnecessary coupling.
- btilly 5y agoThe coupling that I described needs to be in the software because it exists in the real world that the software is trying to describe. However your "compile time" point is important. There is another solution, which is to implement lazy loading of those classes. So you put your import in the method of each that needs to know the other. This breaks the circular dependency and needs more up front memory. However it can also become a maintenance issue where a forgotten import in one function is masked by a successful import in another, until something changes the call and previously working code mysteriously goes boom. It's all tradeoffs.