static void Main(string[] args) { IFactory operFac = new AddFactory(); Operation oper = operFac.CreateOperation(); oper.NumberA = 1; oper.NumberB = 3; double result = oper.GetResult(); }
static void Main(string[] args) { try { IFactory operationFactory = new AddFactory(); Operation operation = operationFactory.CreateOperation(); operation.NumberA = 1; operation.numberB = 5; double result = operation.GetResult(); Console.WriteLine("{0}", result); } catch (System.Exception ex) { Console.WriteLine("您的输入有错: " + ex.Message); } }