我想知道是否可以将抽象类的属性(或函数)值传递给实例类参数?还是我必须创建一个私有成员变量,为其分配数据并将其传递给实例类参数?这听起来令人困惑,因此下面的示例将有助于更好地阐明它。
看看“新的 DealerAccountRepository(MyEnvironmentSetting);” “DatabaseDataDealer”类中的部分。
public abstract class AEnvironmentSetting
{
//Constructor...
protected AEnvironmentSetting(EnvironmentSetting parmEnvironmentSetting)
{
_environmentSetting = new EnvironmentSetting
{
Emulation = parmEnvironmentSetting.Emulation,
Database = parmEnvironmentSetting.Database
};
}
//Member variables...
private EnvironmentSetting _environmentSetting = null;
//Get/Set properties...
protected string MyEmulation { get { return _environmentSetting.Emulation; } } //No need for "set {}" property...
protected string MyDatabase { get { return _environmentSetting.Database; } } //No need for "set {}" property...
//Functions...
protected EnvironmentSetting MyEnvironmentSetting()
{
return _environmentSetting;
}
}
public class DealerAccountRepository : AEnvironmentSetting
{
//Constructor...
public DealerAccountRepository(EnvironmentSetting parmEnvironmentSetting) : base(parmEnvironmentSetting)
{
}
//Functions...
public string Foo_Emulation()
{
return MyEmulation; //This object coming from the abstract class "AEnvironmentSetting"...
}
public string Foo_Database()
{
return MyDatabase; //This object coming from the abstract class "AEnvironmentSetting"...
}
public EnvironmentSetting Foo_EnvironmentSetting()
{
return MyEnvironmentSetting(); //This object coming from the abstract class "AEnvironmentSetting"...
}
}
public class DatabaseDataDealer : AEnvironmentSetting
{
//Constructor...
public DatabaseDataDealer(EnvironmentSetting parmEnvironmentSetting) : base(parmEnvironmentSetting)
{
}
//Get/Set properties...
public DealerAccountRepository DealerAccount { get { return new DealerAccountRepository(MyEnvironmentSetting); } } //No need for "set {}" property...
//Functions...
//N/A...
}