0
It is good practice to call any method within a getter?
Example:
public final class ScannerDeHtm {
private static final String DIR_CEF = DefineDiretorio.getDiretorio() + "CEF";
private static List<String> listaHtmFile;
private static List<Jogo> listaJogos;
private ScannerDeHtm() {}
private static void scanHtmFile() throws IOException {
List<String> listaSorteios;
File arquivoHtm = new File(DIR_CEF + File.separator + "d_megasc.htm");
try {
Scanner scanner = new Scanner(arquivoHtm.toPath());
// ...
}
}
public static List<Jogo> getListaJogos() {
try {
scanHtmFile(); // é boa prática?
} catch (IOException e) {
e.printStackTrace();
}
if (listaJogos != null) {
return new ArrayList<>(listaJogos);
}
return new ArrayList<>();
}
}
The other way would be to insert the scanHtmFile() method into the constructor of this class, or make it public and call it static when using.. But I still prefer:
lista = ScannerDeHtm.getListaJogos();
to
ScannerDeHtm scan = new ScannerDeHtm();
lista = scan.getListaJogos();
So what do you think?
Edit: It is worth noting that this Class in question only exists to return a List with the games and it will be widely used in this program.
I think totally worth what Voce did in the way
getListaJogos()
So if you want to return something different based on the list of games, maybe a filter, or something like that, you don’t need to rewrite the HTML scan. Not to mention that I find more organized each method doing a little bit of the process.– Neuber Oliveira