抽象クラスのプロパティ (または関数) の値をインスタンス クラスの引数に渡すことは可能ですか? または、プライベート メンバー変数を作成し、それにデータを割り当てて、代わりにインスタンス クラスの引数に渡す必要がありますか? それは紛らわしいので、以下の例はそれをより明確にするのに役立ちます.
「new 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...
}