The issue / background
I’ve a mission, BusinessProject, that presently shops some static information in reminiscence utilizing the Singleton sample – we’ll name this class GlobalData
. This mission is utilized in a number of purposes, with completely different necessities on what information needs to be loaded into reminiscence. One utility, lets name this SubProject, solely wants a subset of the info. The opposite mission, MasterProject, calls SubProject in addition to different capabilities inside BusinessProject which require different information in GlobalData
to be obtainable in reminiscence. My objective is to make use of inheritance to keep away from storing the overlapping information twice, in addition to let the mission interfacing with BusinessProject simply outline the necessities wanted by merely calling the specified class.
Simplified Code
public class GlobalData
{
protected static readonly GlobalData _Instance = new GlobalData();
protected DateTime _lastUpdateDate = DateTime.MinValue;
public Dictionary<string, class> Lookup { get; protected set; }
public IList<DateTime> Dates { get; set; }
public Dictionary<string, Record<double>> DataSeries { get; protected set; }
static GlobalData() { }
non-public GlobalData() { }
// every time the Occasion requested, be sure that the info would not must be refreshed
public static GlobalData Occasion
{
get
{
if (!DateTime.Right this moment.Date.Equals(_Instance._lastUpdateDate.Date))
_Instance.LoadData();
return _Instance;
}
}
protected digital void LoadData()
{
...
_lastUpdateDate = DateTime.Right this moment;
}
}
public class MasterData : GlobalData
{
protected static new readonly MasterData _Instance = new MasterData();
... //additional information properties
static MasterData() { }
non-public MasterData() :base() {}
protected override void LoadData()
{
base.LoadData();
... // load additional information properties
}
}
Conclusion
I am searching for any suggestions on my implementation of the issue ! Thanks.