I have an abstract class containing methods that rely on class variables. However, the values โโof these variables are set in classes that inherit from the abstract.
I wrote this so that the variables were set in the constructor - it seemed like this was the hardest thing. But I just feel uncomfortable with this - they look like they should be abstract properties. I just can't say why I feel this way.
Here is a simplified example of what I actually did:
public abstract class TestBase { protected string itemType; } public class TestClass1 : TestBase { public TestClass1() { itemType = ConfigurationManager.AppSettings["TestClass1.ItemType"]; } } public class TestClass2 : TestBase { public TestClass2() { itemType = ConfigurationManager.AppSettings["TestClass2.ItemType"]; } }
So the questions are:
1) Is this bad practice?
2) If so, why and what is better?
3) This is a test class used for regression testing, and not for deployment anywhere. Is there a good reason to set variables at the class level in config, as in the example, or is it good to hardcode them? I am by default always configured.
Cheers, Matt
source share