# Question on Graph

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>
{
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.

• I wonder how you will retrieve any edges from a given graph. There seems to be no method for that. Even if you had such a method, how do you retrieve a list of all vertexes, without doubles? Commented Jan 24, 2014 at 10:53
• @ Doc Brown, I have just given a subset of the actual class that contains only the method that are relevant to the question...Thanks.. Commented Jan 27, 2014 at 13:20