I currently have a cache implementation (using arrays) for the heavy computations performed during the simulation. The structure of the cache is as follows:
The way it works:
CalculationsAbstract calculationsCache = new CalculationsCache();
// Constructor of CalculationsCache
public CalculationsCache()
{
this.Proxy = new Calculations();
Proxy.Proxy = this;
}
calculationsCache.CalculateValue1();
// Checks "Value1" array for existing value, if not, the actual computation is called
// via Proxy object, value retrieved is cached in array then returned to user.
Now, I'm trying to add new computations which are specific to a certain scenario, and wouldn't be appropriate for them to be placed in CalculationsAbstract
, Calculations
and CalculationsCache
, however ScenarioA would still use existing calculations in the old classes.
I'm trying to add the new calculations and their arrays in new classes named ScenarioACalculations
and ScenarioACalculationsCache
, just like it was done for Value1, Value2,...etc but I'm confused as to how these new classes would fit into the existing model.
This is what I tried to do:
internal interface IScenarioACalculations
{
float GetScenarioAValue5();
}
ScenarioACalculations : Calculations, IScenarioACalculations
ScenarioACalculationsCache : CalculationsCache, IScenarioACalculations
Given that throughout my project, I only hold a reference to type CalculationsAbstract
(as in the code example above), and I can't cast my IScenarioACalculations
object to CalculationsAbstract
, what would be the best way to add ScenarioA calculations and possibly ScenarioB...etc in the future ?
Sorry for making this long.
Thank you.