I'm not so sure about what's the best approach to model this problem in the object oriented world.
Suppose I have to represent a graph and it's nodes in Java and suppose I to visit the graph using a depth first search (DFS).
What the best approach in Software engineering among these two:
-
Create a class
Node
, a classGraph
and a classGraphsFunctions
where theGraphsFunctions
class contains theDFS
method which takes the Graph and a Node as parameters. Something like this:public void DFS(Graph g, Node n)
and the callnew GraphsFunctions().DFS(new Graph(), new Node())
-
Create a class
Node
, a classGraph
where theGraph
class contains theDFS
method which takes only the Node as parameter. Something like this:public void DFS(Node n)
and the callnew Graph().DFS(new Node())
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?
Aucun commentaire:
Enregistrer un commentaire