I'm trying to implement interface for Node class in CSharp.
NodeInterfaces.cs
public interface INode<T>
{
T Value { get; set; }
Node<T> Left { get; set; }
Node<T> Right { get; set; }
}
Nodes.cs
public class Node<T> : INode<T>
{
T Value { get; set; }
Node<T> Left { get; set; }
Node<T> Right { get; set; }
}
BUT cyclic dependency error occurs I've tried to understand how can I implement it in another way, but I have no idea...
So The only solution I've come to is
NodeInterfaces.cs
public interface INode<T, N> where N : class
{
T Value { get; set; }
N Left { get; set; }
N Right { get; set; }
}
Nodes.cs
public class Node<T> : INode<T>
{
T Value { get; set; }
Node<T> Left { get; set; }
Node<T> Right { get; set; }
}
Is it a good practice, or which ways of fixing this cycling dependecies problems are applicable too? I need your advices how would be better to implement this interface, or it would be better without any interfaces (but I want to do it)
INode<T, N> where N : INode<T,N>.