public SuperCalc CreateCalc(string strCalcType) { SuperCalc InnerCalc = null; switch (strCalcType) { case "+": InnerCalc = new AddCalc(); break; case "-": InnerCalc = new MinusCalc(); break; case "*": InnerCalc = new MultiCalc(); break; case "/": InnerCalc = new DiviCalc(); break; default: break; } return(InnerCalc); }
static void Main(string[] args) { Factory myCalcFac = new Factory(); SuperCalc myCalc = myCalcFac.CreateCalc("+"); double result = myCalc.AcceptInput(5.0, 9.0); Console.WriteLine("5.0 + 9.0 = {0}", result); Console.ReadKey(); }