Reputation: 3729
I'm wondering is is it possible to pass on abstract class's property (or function) values a instance class argument? Or do I have to create a private member variable, assign data to it and pass this one to the instance class argument instead? That's sounds confusing, so the example below will help to clarify it better.
Take a look at the "new DealerAccountRepository(MyEnvironmentSetting);" section in the "DatabaseDataDealer" class.
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...
}
Upvotes: 2
Views: 2463
Reputation: 11597
if you are asking if a method can take an abstract object like this:
private void DoSomething(AEnvironmentSetting a)
then yes, it can, and you can use every property and method there is in the abstract class including calling abstract method. however, whoever calls this method will have to send an instance of a calss inherits the abstract class like so:
DatabaseDataDealer d = new DatabaseDataDealer ();
DoSomething(d);
and if an abstract method will be call from DoSomething
then implementation of DatabaseDataDealer
will be called
in the constructor you can call the base and you will get to the abstract constructor. in the end let me just say the best way to learn this is to try. compile and run your code and put a break point to see how it goes and through which steps
Upvotes: 1