User input in constructor bad practice?
I am making some System.out.println output only programs at the moment.
I am making objects which always require 3 variables to be user-defined before any work is carried out using these objects.
I have a feeling it is bad practise to include something like:
Are my thoughts correct?
System.out.println("What is variable a?");
variableA = scanner.nextInt();
System.out.println("What is variable b?");
variableB = scanner.nextInt();
System.out.println("What is variable c?");
variableC = scanner.nextInt();
If so, is it therefore best to just initialise the 3 variables in the constructor using 3 random (probably 0) variables and then just ensuring to write this code elsewhere?
Re: User input in constructor bad practice?
The constructor is used to create an object. What usually happens is your driver class will gather all the information and pass the data as parameters to the constructor. The constructor then initialises instance variables with the data passed in. So, making the constructor do the work of gathering the data is a bad design.