I’m fairly new to Java so forgive me for asking what may appear to be a stupid question.
I am writing a simple ‘user login’ program. To check whether the username and password match, I could either use a simple boolean variable or use a boolean method and return the value as true or false.
public boolean match() {
if(userField.getText().equals(testUser)&&passField.getText().equals(testPass))
return true;
else
return false;
}
Above is a very simple example of using a boolean method.
My question is, as a rule of thumb, what is the more favourable thing to use, a boolean method or a variable? I understand that this might be more of a personal preference thing for the programmer but I don’t understand why you would choose one over the other.
Ideally you should abstract out the match method in to an interface and have implementations override the match() method