So I really like data structures and I've been working on a class library that implements different types of graphs in different ways. One of the stumbling blocks I've had is trying to easily combine specific features of different types of graphs.
To clarify, let's say I have an interface named IGraph<T>, where T is the data that each node holds. Now, I also want to have interfaces for IUndirectedGraph<T>, IDigraph<T>, and IWeightedGraph<T,E>, where E is the type used as a weight.
I'd like to be able to provide different implementations of the same types of graph. For example, I'd like to be able to provide a class that uses an adjacency list and a class that uses an adjacency matrix. The classes may have slightly different implementations of certain algorithms. As a simple example, determining the neighbors of a given object would be different in each implementation.
So, let's say I have these two class declarations:
class WeightedAdjacencyListGraph<T,E> : IUndirectedGraph<T>, IWeightedGraph<T,E>
class WeightedAdjacencyMatrixGraph<T,E> : IUndirectedGraph<T>, IWeightedGraph<T,E>
I'd like to be able to declare a variable type that can store objects of both of these classes, yet keep the functionality defined in all interfaces. Basically, I want to be able to declare a variable type like:
<IUndirectedGraph<object>+IWeightedGraph<object,double>> MyGraph = new WeightedAdjacencyListGraph<object,double>();
MyGraph = new WeightedAdjacencyMatrixGraph<object,double>();
Obviously, the variable type declaration is not correct C# syntax, but what would I put here? Do I have to create a new interface for each combination of interfaces? Is my design fundamentally flawed, and if so, what should I do to rectify it?
Edit: I've decided to create different namespaces for directed/undirected graphs, and to store common interfaces (such as IWeightedGraph<T,E>) in the root namespace. I'll then basically create the combined interfaces I mentioned above (which were also noted in the answers). I figure the directed/undirected graphs aren't likely to share a whole lot in common when it comes to the fun algorithms anyways.