Is constructor a good practice?

Constructors are meant to initialize the data fields in the object. Given the choices, the second approach seems more correct. Although what might be better is to include the doDFS method in your graph object. It’s usually bad practice to create an entire class for a single simple function .

Read more