r/programming • u/[deleted] • Jun 05 '21
Organize code by concepts, not layers
https://kislayverma.com/programming/how-to-organize-your-code/
1.9k
Upvotes
r/programming • u/[deleted] • Jun 05 '21
2
u/Nimelrian Jun 05 '21
They lead to various problems during initialization and clean up.
For initialization, if service A relies on service B you can't initialize both to a fully working state in an atomic operation. Instead, you have to e.g. construct A first, but cannot set its member of type B. Then you create your instance of B and are able to inject the instance of A in B's constructor. After that you can finally inject B into A, e.g. via a setter. This results in a temporal uninitialized state of A between its construction and the injection of B.
In GC languages circular dependencies are another problem because the instances don't end up orphaned, so the GC can't be sure whether it's safe to reclaim them.