I have a simulation that runs at a specific height and a specific temperature:
interface ISimulation
{
string Name { get; }
int Height { get; }
int Temperature { get; }
void Generate();
}
The Generate()
process for a simulation typically involves multiple steps:
void Generate()
{
GenerateStep1();
GenerateStep2();
GenerateStep3();
}
Now, it is possible for the user to specify multiple heights and/or multiple temperatures.
In this case, multiple simulations (sub-simulations) are spawned off, one per each height/temperatue combination.
interface IMultiSimulation
{
string Name { get; }
int[] Heights { get; }
int[] Temperatures { get; }
void Generate();
}
In this case however, the Generate() of the sub-simulation would have to change as follows:
- If multiple temperatures are specified, then
GenerateStep2()
needs to be performed only once for all sub-simulations, and not per temperature. - If multiple heights are specified, then:
GenerateStep1()
is performed first on all sub-simulations.- Step2 and Step3 are then performed.
- It is possible to have a grand simulation with multiple heights AND multiple temperatures. This means that 2 above criteria need to be satisfied.
I've been trying to use the decorator pattern but with no success. What are some tips I could use to handle the complexity of my code?
Thanks.
Aucun commentaire:
Enregistrer un commentaire