3
After a login effective in the application I am building I return a boolean[]
with all the accesses that the user has.
// Armazena o controle de acesso do usuário
LoginDAO logindao = new LoginDAO(conexao);
boolean[] acessos = logindao.controleAcesso(codigoUsuario);
Now when applying these accesses, instantiating only what can be used, I have a code full of if
s (totalling 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 interface Canvas:
public interface Tela {
Tab constroi();
}
There is a design pattern that allows me to know which screen to instantiate without needing that amount of if
s? Or any technique that allows me to simplify this code.
The intention is to really save memory creating on demand, I have 4 panels each with 3-4 Screens. The most "heavy" part is in the building(), perhaps instantiating everything and using only the necessary?
– Gustavo Fragoso