public static Operation CreateOperation(string strOperator) { Operation opr = null; switch (strOperator) { case "+": opr = new OperationAdd(); break; case "-": opr = new OperationSub(); break; case "*": opr = new OperationMul(); break; case "/": opr = new OperationDiv(); break; default: throw new Exception("运算符输入错误!"); } return(opr); }
/// <summary> /// 只需输入运算符,工厂就能实例化出合适的对象,通过多态,返回父类的方式实现了计算器的结果 /// </summary> /// <param name="operate">运算符</param> /// <returns></returns> public static Operation createOpeate(EnumOperator op) { Operation oper = null; switch (op) { case EnumOperator.Add: oper = new OperationAdd(); break; case EnumOperator.Minus: oper = new OperationSub(); break; case EnumOperator.Multiply: oper = new OperationMul(); break; case EnumOperator.Divide: oper = new OperationDiv(); break; default: break; } return(oper); }
public static Operation createOperation(string item) { Operation temp = null; switch(item) { case "+": temp = new OperationAdd(); break; case "-": temp = new OperationSub(); break; case "*": temp = new OperationMul(); break; case "/": temp = new OperationDiv(); break; } return temp; }
public static Operation createOperate(string operate) { Operation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return(oper); }
public static Operation createOperation(string item) { Operation temp = null; switch (item) { case "+": temp = new OperationAdd(); break; case "-": temp = new OperationSub(); break; case "*": temp = new OperationMul(); break; case "/": temp = new OperationDiv(); break; } return(temp); }