Circular dependency
A circular or cyclic dependency is a situation where two or more independent modules or components rely on each other to function properly. This is referred to as mutual recursion. Circular dependency generally occurs in a modular framework while defining a dependency between modules or components.
The term circular dependency is very common across domain models where a set of objects are associated with each other. Circular dependencies between classes are not necessarily harmful. In fact, in particular situations, they are appropriate. Take an example of an application where you are dealing with domain objects such as a student and a course. You probably need a Student
class that gets courses a student has enrolled in, and a Course
class that gets a list of students enrolled on that course. It is clear that the Student
and the Course
classes are interdependent, but if circular dependency is required in this case, then taking a chance to remove it may introduce some other...