Strategy Pattern
Example
public enum SimulationMethod {
Quick, Complex
}
public class StockSimulatorUsingSwitch {
public double SimulateNetGainOrLoss(string nasdaqCode, SimulationMethod method) {
switch (method) {
case SimulationMethod.Quick:
return 0;
case SimulationMethod.Complex:
return 1;
default:
throw new ArgumentOutOfRangeException("method");
}
}
}
StockSimulatorUsingSwitch s = new StockSimulatorUsingSwitch();
doublce simulatedValue = s.SimulateNetGainOrLoss("XXXX",
SimulationMethod.Quick);Last updated