Consider the following class:
class Something : ISomething {
public void DoesSomething(int x) {
if (x == 0) {
x = 1;
}
}
}
I want to of course remove the magic number - my unit tests are passing etc... but I want to refactor the horrible magic number out.
I'm using C# but I guess this problem is pretty generic. Reading from a config file (xml file) is done by something like:
ConfigurationManager.AppSettings["MyOldMagicNumber"]...
Which of course, would be a sod to test. I could easily make a private function in this class that is marked virtual. Its purpose to encapsulate that above code. This would allow me to access in my unit tests to override and plug in my own value.
My question is -
Is this bad what I'm doing? See title.
Edit:
This is for a game - therefore is more than likely during development the values will change often and doing a re-build will be a chore. I should have mentioned that, the above code is generic, I made it so to keep the question as simple as possible. A bit of context though - that '0' is the game area bounds.
Thanks in advance.