I have an idea that reading values from config files instead of using hard code values, but I’m not sure it is a good practice or not.
First I created a utility class:
public class ConfigValues
{
public static int Read(string key, int defaultValue){....}
public static string Read(string key, string defaultValue){....}
public static bool Read(string key, bool defaultValue){....}
...
}
The Read function tries to read value for the given key. If the key doesnot exist or the value has bad format, it returns the default value. And I’m going to use this class like:
public class MyClass
{
private int _age = ConfigValues.Read("Com.MyClass.Age", 0);
...
}
So that, we can make almost all variables in the application customizable.
Will it be a good practice?
Please comment it for free.
People who think you should make things configurable:
People who think differently:
The answer comes down to your requirements: why are you setting this value here?
Etc. It’s not a simple yes-it’s-good or no-it’s-bad answer.