Is it good practice to call any method inside 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 it is to be used. But I still prefer:
lista = ScannerDeHtm.getListaJogos();
a
ScannerDeHtm scan = new ScannerDeHtm();
lista = scan.getListaJogos();
So, what do you think?
Edit: It is worth mentioning that this Class in question only exists to return a List with the games and it will be used extensively in this program.