当我在学习嵌套类并遇到问题时。就在那时有人告诉我我需要使用界面。在实现接口的过程中,我了解到接口不允许构造函数或传递参数参数。所以,我正在考虑抽象,但我不确定实现它们并保持简单。
在下面的源代码中。环境设置填充在控制台项目中,并传递给 DLL 项目中的数据库类。
问题 #1 - 是否可以为更简单的脚本抽象环境设置?
问题 #2 - 是否使用嵌套类,如何保护 DealerRepository 类(使其对控制台项目不可见?(我猜是抽象的)。
问题 #3 - DealerRepository 类需要抽象还是什么?
我想要在这里保护/隐藏控制台项目中的 DealerRepository 类,而不必通过嵌套类重复传递 EnvironmentSetting 类/模型。
谢谢...
//EnvironmentSetting.cs
namespace zTestcase1.Model {
public class EnvironmentSetting : IDisposable
{
public EnvironmentSetting() { } //Constructor...
public void Dispose() { } /Dispose...
//Member variables...
private string _emulation = "";
private string _application = "";
private string _database = "";
//Get/Set properties...
public string Emulation { get {return _emulation;} set {_emulation = value;} }
public string Application { get {return _application;} set {_application = value;} }
public string Database { get {return _database;} set {_database = value;} }
}
}
//DealerRepository.cs
namespace zTestcase1.Data.Dealer
{
public class DealerRepository : IDisposable
{
public DealerRepository(EnvironmentSetting parmEnvironmentSetting) {
_environmentSettingA = parmEnvironmentSetting;
} //Constructor...
public void Dispose() { } //Dispose...
//Member variables...
private EnvironmentSetting _environmentSettingA = "";
//Get/Set properties...
//N/A...
//Functions...
public string EnvironmentResponse()
{
return "Emulation - " + _environmentSettingA.Emulation + ", Application - " + _environmentSettingA.Application + ", Database - " + _environmentSettingA.Database + "";
}
public string DealerProifle_Lookup(string parmName)
{
return "(DealerProfile-Lookup) - " + parmName;
}
public string DealerProfile_Save(string parmName)
{
return "(DealerProfile-Save) - " + parmName;
}
}
}
namespace zTestcase1.Library
{
/*public class Database : IDisposable
{
//Class...
public class DataDealer : IDisposable
{
//Constructor...
public DataDealer(EnvironmentSetting parmEnvironmentSetting)
{
_environmentSettingA = parmEnvironmentSetting;
}
//Dispose...
public void Dispose() { }
//Member variables...
private EnvironmentSetting _environmentSettingA = null;
private DealerRepository _dataDealer = null;
//Get/Set properties...
public DealerRepository Dealer { get { if (_dataDealer == null) { _dataDealer = new DealerRepository(_environmentSettingA); } return _dataDealer; } }
//Functions...
//N/A...
}*/
//Constructor...
public Database(EnvironmentSetting parmEnvironmentSetting)
{
_environmentSettingB = parmEnvironmentSetting;
}
public void Dispose() { } //Dispose...
//Member variables...
private EnvironmentSetting _environmentSettingB = null;
//private DataDealer _dataDealerB = null;
private DealerRepository _dataDealerC = null;
//Get/Set properties...
//public DataDealer Dealer { get { if (_dataDealerB == null) { _dataDealerB = new DataDealer(_environmentSettingB); } return _dataDealerB; } }
public DealerRepository Dealer { get { if (_dataDealerC == null) { _dataDealerC = new DealerRepository(_environmentSettingB); } return _dataDealerC; } }
//Functions...
//N/A...
}
}
namespace zTestcase1.Sample1.Console
{
class Program
{
static void Main(string[] args)
{
EnvironmentSetting environmentSettting = new EnvironmentSetting();
environmentSettting.Application = "DOS Console";
environmentSettting.Database = "Not yet hooked up";
environmentSettting.Emulation = "Development";
Database _libraryDatabase = new Database(environmentSettting);
//var test1 = _libraryDatabase.Dealer.Dealer.DealerProifle_Lookup("Best Dealer Cars Buy");
var test2 = _libraryDatabase.Dealer.DealerProifle_Lookup("Best Dealer Cars Buy");
System.Console.WriteLine(_libraryDatabase.Dealer.EnvironmentResponse() + " [=] " + test2);
System.Console.ReadLine(); //To pause the console...
}
}
}