What term is used to describe when two classes are dependent on each other?

I have the following two classes in C #:

public class MyFirstClass : IMyFirstClass
{
    MySecondClass mySecondClass;
    public MyFirstClass(IMySecondClass mySecondClass)
    {
        this.mySecondClass = mySecondClass;
    }

    public MyFirstClass() : this(new MySecondClass()){}
}

public class MySecondClass : IMySecondClass
{
    MyFirstClass myFirstClass;
    public MySecondClass(IMyFirstClass myFirstClass)
    {
        this.myFirstClass = myFirstClass;
    }

    public MySecondClass() : this(new MyFirstClass()){}
}

      

You will notice that when a default constructor for any of these classes is created that the system will crash due to infinite instances that have to happen.

Is there an official term that is used to describe this problem?

+2


source to share


2 answers


This is called a circular reference :



A circular reference, sometimes referred to as a traversal, is a series of references where the last object refers to the first, thus causing a whole series of references to be unusable.

+6


source


I had this the other day and found this:

What is a circular dependency and how to solve it?



@Andrew Hare above is absolutely correct, but the alternative term is "circular dependency".

+1


source







All Articles