I have several classes that have to connect to something before they can do anything. So ideally, I create a base class with a constructor with 1 parameter. Then these classes inherit from this base class, something like this:
public class BaseErase
{
private string _connectionString;
public string ConnectionString
{
get
{
return _connectionString;
}
set
{
_connectionString = value;
}
}
public BaseErase(string connectionString)
{
ConnectionString = connectionString;
}
//public void SetConnection(string connectionString)
//{
// ConnectionString = connectionString;
//}
}
Then my derived class would inherit from BaseErase, something like this:
class ToEraseClass : BaseErase
{
public void GetData()
{
string connect = ConnectionString;
Console.WriteLine(connect);
}
}
Then finally, I instantiate my class and call GetData():
ToEraseClass toErase = new ToEraseClass(ConnectionString);
toErase.GetData();
Unfortunately, constructors are not inherited, so none of this works. I know the fix to this, but it requires that I modify every single class.
My question is, what's the purpose of inheritance here?
Thanks.