I am trying to implement a graph data structure in C#. I have the following interfaces:
public interface IVertex<TValue>
{
TValue Value { get;}
VertexList<IVertex<TValue>> Neighbours { get;}
int InDegree { get;}
int OutDegree { get;}
}
public interface IWeightedEdge<TValue, TWeight>
{
IVertex<TValue> source { get;}
IVertex<TValue> destination { get;}
TWeight weight { get; }
}
public interface IWeightedGraph<TVertexValue, TEdgeWeight>
{
bool AddVertex(TVertexValue value);
TVertexValue RemoveVertex(IVertex<TVertexValue> vertex);
bool RemoveVertex(TVertexValue value);
bool AddEdge(IVertex<TVertexValue> source, IVertex<TVertexValue> dest, TEdgeWeight weight);
bool RemoveEdge(IVertex<TVertexValue> source, IVertex<TVertexValue> dest);
}
From this, you can see that it is the responsibility of the Vertex class (the class implementing IVertex interface) to tell about its adjacent vertices (Neighbors function), its in degree, out degree etc. While I was designing this, I was told by a friend of mine that the Graph class (the one that will implement IGraph) should take the responsibility of operations like retrieving adjacent vertices ,finding the in/out degrees etc. His point is that the above operations are valid only when a vertex becomes part of a Graph. But my point is that a Vertex is standalone; it can exist even outside of a graph. So, the vertex should provide the operations on it.
Which one you think is correct? Please share your thoughts on this.