I'm designing an OO graph library and at the moment I'm trying to figure out the design for a
GraphEdge class. I've added setters and getters for it's nodes, direction and weight. This seemes perfectly reasonable.
Then I've started working on the
Graph class and I've come to the need of knowing if the particular edge is adjacent to the particular node.
And now I doubt if I should add a
isAdjacentTo(Node) method to the
GraphEdge class or I should create a
GraphUtil class(*) and add static
edgeIsAdjacentToNode(Edge,Node) method to it.
On the one hand, I can not see any additional reasons for changing
GraphEdge if I stick to the first option. On the other hand, this seems to me like kind of second responsibility added to the class.
Also if I stick to the first option this will probably violate the
Open-Close Principle. The
GraphEdge is not closed for changes, since later I will need to add
linksNodes(Node,Node) method to it and maybe some others later.
The questions are:
isAdjacentTo(Node)method to the
GraphEdgeclass violates the SRP?
(*) I stick to pure OO style with no free functions