#How to have user inputs as object parameters?
28 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @stray snow! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Whenever you have an either/or, try and tell yourself you're wrong and what should be done is neither. Have a dedicated class for that.
Both work tho
So a dedicated class for user input?
So this constructor is bad?
What would that dedicated class look like?
it's extremely bad mojo to put IO or interaction inside a constructor
public final class FlagInput {
public static Flag fromUser(Scanner scanner) {
// the steps here
}
}
And then I call that method in the constructor I sent?
Of course not, it's the other way around. It calls the constructor
professor told me that a constructor shouldn’t have more than
3-5 parameters
I did this entire thing to avoid it
Like constructors in general shouldn’t have more than 3-5 parameters
It's not untrue. Ideally you'd design subparts rather than have that many fields
You could also pick a minimum amount of fields that are absolutely necessary for the self-consistency of your class, and have the others set with setters
@mint canopywhy is it a final class?
It's just that utility classes, classes that contain only static members, shouldn't be instantiated. To avoid that, they should be final (extending them should make no sense) and preferably they should make their constructor private so it isn't used.
I forgot to mention
That
Doesn't matter, we were talking about my utility class
Ty

