Without a context about the problem, it’s hard to say with precision.
But looking only at the code, I understand that at the time of authentication you will perform a comparison between the values of the Manager and values that came from the parameters.
Therefore, the login
:
//novo método, recebendo dois params
public boolean autentica(String login, int senha) {
//implementacao omitida
}
Like the password, already existing on Gerente
:
private int senha;
It must be a private field of Gerente
. Thus:
private String login;
private int senha;
This is because login
and senha
belong at the Gerente
.
Then we would have something like this, using the code above:
Gerente gerente = new Gerente();
gerente.setSenha("senha");
gerente.setLogin("login");
boolen loginValido = gerente.autenticar("outroLogin", "outraSenha");
Or better yet, without the sets
and using builder:
Gerente gerente = new Gerente("login", "senha");
boolen loginValido = gerente.autenticar("outroLogin", "outraSenha");
If you want to evolve this model, usually login
and senha
are associated with a Usuario
. In this way, it would be interesting that Gerente
had a Usuario
with login and password.
There is no "attribute"
login
in this code.– Maniero