After an effective login in the application I'm building I return a boolean[]
with all the accesses the user has.
// Armazena o controle de acesso do usuário
LoginDAO logindao = new LoginDAO(conexao);
boolean[] acessos = logindao.controleAcesso(codigoUsuario);
Now when it comes to applying these accesses, instantiating only what can be used, I have a code full of if
s (totaling 17) that I would like to remove or simplify, see:
/**
* Aplica o controle de acesso às telas do sistema. Criando apenas
* as necessárias.
* @param acessos Lista com os acessos
*/
private void aplicarAcessos(boolean[] acessos) {
if(acessos[0]) {
tabAcervo = new TabPane();
ObservableList<Tab> abasAcervo = tabAcervo.getTabs();
if(acessos[1]) {
abasAcervo.add(new TelaMovimentacao().constroi());
}
if(acessos[2]) {
abasAcervo.add(new TelaConsulta().constroi());
}
if(acessos[3]) {
abasAcervo.add(new TelaReserva().constroi());
}
}
// [...]
}
Note: All Screens obey the Screen interface:
public interface Tela {
Tab constroi();
}
Is there a design pattern that lets me know which screen to instantiate without needing this amount of if
s? Or some technique that will allow me to simplify this code.