A direct dependency is formed when two classes or files have dependency over each other. The dependency can be caused by using variables or function calls.
Impact
- Cyclic dependency creates tight coupling between these classes and it is hard to reuse as separate units.
- Sometimes, circular dependency may cause memory leaks by preventing garbage collector to do their work.
Example(s)
C1 and C2 are the components that are directly dependent on each other.
Guidelines
- Cyclic dependency can be removed by using design patterns like observer or simply introducing interfaces.
- The code can be refactored to separate out the common logic to make those 3 classes where 2 classes depend on a 3rd class.