I hope this is decent question, the background is that I have an abstract base class, this base class has some concrete method implementations which are accessible to derived classes. The base class and the all of the derived classes have a set of unique variables. All of the common functionality is in the concrete methods of the base class (Which are NOT virtual so they cannot be overridden) Each of the derived classes are also getting some of these values from the AppSettings in the App.Config file.
So my question is this, Where is the best place to put these const values that would be following best practices and will allow the code to be properly testable (this last piece is very important)?
The 2 options that I know are:
1) Create a static config class that has all of the values for each of the classes. This is great for the normal consts, but retrieving the App.Config values will fail unless, either the Test project has the values in its own App.Config file (This seems like a dirty hack to me)
2) The other option is to declare them and get the values settings in the using class, this adheres to the declare it where you use it principle, but it makes the class un-testable unless you again add the values to the App.Config of the test project.
public abstract class BaseClassA
{
private const string PATH = "\ParentClassPath\" // Option 2
private int _var1;
private string _var2;
public BaseClassA(int param1, string param2)
{
_var1 = param1;
_var2 = param2;
}
public int Param1Prop { get; private set;}
public string Param2Prop { get; private set; }
protected string Method1(string value1, string value2, string value3)
{
Directory.CreateDirectory(StaticClass.PATH); //Option 1
return Path.GetDirectoryName(PATH) //Option 2
}
}
public class DerivedClassB
: base(1, "param2")
{
private const string PATH = "\DerivedClassPath\" // Option 2
public BaseClassA(int param1, string param2)
{
_var1 = param1;
_var2 = param2;
}
public int Param1Prop { get; private set;}
public string Param2Prop { get; private set; }
protected string Method1(string value1, string value2, string value3)
{
Directory.CreateDirectory(StaticClass.DERIVED_PATH); //Option 1
return Path.GetDirectoryName(PATH) //Option 2
}
}