Most times, I don’t start out with configuration file(s)…..what I do is simple, I create a class with static variables and I assign them values. After I finished the project, I will then create a configuration file and then my class will have a constructor which I will call from my Bootstrap class or main class. What the constructor does is simple…assign values to the static variables from the configuration file. This is something I have been doing for a while and today I felt its just awkward to do things like this….I think there should be a better way to do this bearing in mind that I still don’t want to start developing with a predefined configuration file….I want to be able to determine either or not I want to use a configuration file only at the end of the project…..so I devised a new method. instead of static variables and then a constructor, I used static methods. The methods could just return a value(especially during tests) or read from the configuration file and return the value read.
For example,
public static String getHost() {
return “localhost.localdomain”;
//read this value from the configuration file.
}
I have a Configuration File helper that I use to read from configuration files.
This works for me now, and I think I am gonna be using it for another x years. 🙂