It's common to implement binary search trees with an internal Node classpublic class BinarySearchTree<TKey, TVal>{    class Node    {        public readonly TKey Key;        public readonly TVal Val;        public Node Left, Right;        public Node(TKey key, TVal val, Node left = null, Node right = null)         {            Key = key; Val = val; Left = left; Right = right;        }    }    private Node treeRoot;}This is nice because it hides client code from being able to directly modify the tree. It might be the case, however, that we want to expose traversal of the tree (e.g. for printing). In this sense, it might make sense to pull the Node class out of BinarySearchTree, and redesign Node to use the visitor design pattern. interface ITreeVisitor<TKey, TVal>{    void Visit(Node<TKey, TVal> node);}class InOrderTreeVisitor<TKey, TVal> : ITreeVisitor<TKey, TVal>{    public void Visit(Node<TKey, TVal> node)    {        if (node == null) return;        node.Left.Accept(this);        // do something to node        node.Right.Accept(this);    }}public class Node<TKey, TVal>{    public Node<TKey, TVal> Left    {        get;        internal set;    }    public Node<TKey, TVal> Right    {        get;        internal set;    }    public readonly TKey Key;    public readonly TVal Val;    public Node(TKey key, TVal val, Node<TKey, TVal> left = null, Node<TKey, TVal> right = null)    {        Key = key; Val = val; Left = left; Right = right;    }    public void Accept(ITreeVisitor<TKey, TVal> v)    {        v.Visit(this);    }}public class BinarySearchTree<TKey, TVal>{    public Node<TKey, TVal> Root    {        get;        private set;    }}The trouble with this is that the visitors have to be generic. This doesn't really make sense. A visitor isn't a container, and doesn't really need to know anything about keys or values. Is there any way to make ITreeVisitor non-generic?
Exposing nodes in a generic binary search tree implementation to visitor pattern
c#;design;generics