我有一個類,它有一個公共屬性「的AppController」,具體如下:派生類使用基類的屬性?
public class FAST
{
#region Props
public AppController.AppControllerClass appController = new AppController.AppControllerClass();
#endregion
#region Contructors
public FAST(AppController.AppControllerClass appcontroller)
{
this.appController = appcontroller;
}
#endregion
}
我還有一個幾類,其中我想用快速的AppController中,上述class.They樣子:
public class Forecast
{
#region Properties
private int _forecastnumber;
public int ForecastNumber
{
get { return _forecastnumber; }
set { _forecastnumber = value; }
}
private DateTime _startdate;
public DateTime StartDate
{
get { return _startdate; }
set { _startdate = value; }
}
private DateTime _enddate;
public DateTime EndDate
{
get { return _enddate; }
set { _enddate = value; }
}
private DateTime _deadline;
public DateTime Deadline
{
get { return _deadline; }
set { _deadline = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private string _type;
public string Type
{
get { return _type; }
set { _type = value; }
}
private string _description;
public string Description
{
get { return _description; }
set { _description = value; }
}
private string _status;
public string Status
{
get { return _status; }
set { _status = value; }
}
#endregion
#region Constructors
public Forecast()
{
}
#endregion
#region Methods
public static void InsertForecast(Forecast forecast)
{
try
{
this.appController.Execute(appController.nDC.FASTData.InsertForecast(forecast.StartDate, forecast.EndDate, forecast.Deadline, forecast.Type, forecast.Name, forecast.Description, forecast.Status));
}
catch (Exception ex)
{
this.appController.LogError(ex);
}
}
#endregion
}
我希望能夠一次申報快班,通過在AppController中,然後自由地使用我的其他類,他們會用快班的AppController的。
這可以完成嗎? (繼承?)
感謝您的任何幫助。
感謝。我不喜歡這種方法是我每次使用預測類或創建類的實例時都需要設置appController。 – Rivka 2012-02-21 22:22:39
你有沒有考慮過依賴注入?有一些很好的.NET庫,比如Ninject。 – 2012-02-21 22:28:29