3
In other languages like Python it is possible to perform programming logic in the configuration files and in Java this is not allowed because it is a compiled language.
I decided to encapsulate the file settings .properties
in a Java object, with this I have the advantage of being able to validate the file information, generate programming logic and even use the Eclipse autocomplete but I have the disadvantage of not being able to create properties dynamically, so I have to wonder if this is good practice or just something to further complicate development.
Ex:
File config.properties
email.user=user
email.host=smtp.email.com
email.auth=true
Class:
public class Config {
private String emailUser;
private String emailHost;
private Boolean emailAuth;
public Config() {
Properties properties = new Properties();
try {
properties.load(Config.class.getResourceAsStream("/config.properties"));
emailUser = properties.getProperty("email.user");
emailHost = properties.getProperty("email.host");
emailAuth = Boolean.valueOf(properties.getProperty("email.auth"));
} catch (IOException e) {
e.printStackTrace();
}
}
//Somente Gets
}
Welcome to SOPT! I want to praise the fact that your first intervention on the site have been through a reply.
– ramaral
+1 Good points.
– utluiz