I really like data structures, and I worked on a class library that implements different types of graphs in different ways. One of the stumbling blocks that I had is to easily combine the specific functions of different types of graphs.
To clarify, let's say I have an interface named IGraph <T>, where T is the data that is stored in each node. Now I also want to have interfaces for IUndirectedGraph <T>, IDigraph <T>, and IWeightedGraph <T, E>, where E is the type used as the weight.
I would like to provide various implementations of the same types of graphs. For example, I would like to provide a class that uses an adjacency list and a class that uses an adjacency matrix. Classes can have slightly different implementations of certain algorithms. As a simple example, the definition of the neighbors of a given object will 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 would like to be able to declare a type of variable that can store objects of both of these classes, but retaining the functionality defined in all interfaces. Basically, I want to be able to declare a variable type, for example:
<IUndirectedGraph<object>+IWeightedGraph<object,double>> MyGraph = new WeightedAdjacencyListGraph<object,double>();
MyGraph = new WeightedAdjacencyMatrixGraph<object,double>();
, #, ? ? , , , ?
: / ( IWeightedGraph < T, E > ) . , ( ). , / , .