title: How to implement Graph search (DFS) with Object Oriented design
body: <p>I'm not so sure about what's the best approach to model this problem in the object oriented world.</p>
  
  <p>Suppose I have to represent a graph and its nodes in Java and suppose I want to traverse the graph using a depth first search (DFS).</p>
  
  <p>What is the best approach in Software engineering among these two: </p>
  
  <ul>
  <li><p>Create a class <code>Node</code>, a class <code>Graph</code> and a class <code>GraphsFunctions</code> where the <code>GraphsFunctions</code> class contains the <code>DFS</code> method which takes the <code>Graph</code> and a <code>Node</code> as parameters. Something like this: <code>public void DFS(Graph g, Node n)</code> and the call <code>new GraphsFunctions().DFS(new Graph(), new Node())</code></p></li>
  <li><p>Create a class <code>Node</code> and a class <code>Graph</code> where the class <code>Graph</code> contains the method <code>DFS</code> which only takes a <code>Node</code> as a parameter. Something like this: <code>public void DFS(Node n)</code> and the call <code>new Graph().DFS(new Node())</code></p></li>
  </ul>
  
  <p>I would rather use the first of the two options but I can't say why it's the best for me. Can you tell me what makes the best choice, actually the best?  </p>