Esempio n. 1
0
        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;

            default:
                break;
            }
            return(oper);
        }
        public static Operation CreateOperation(string operate)
        {
            Operation tempOperation = null;

            switch (operate)
            {
            case "+":
                tempOperation = new OperationAdd();
                break;

            case "-":
                tempOperation = new OperationSub();
                break;

            case "*":
                tempOperation = new OperationMul();
                break;

            //进行相应的异常处理
            case "/":
                tempOperation = new OperationDiv();
                break;

            default:
                throw new Exception("输入的符号不正确");
                break;
            }

            return(tempOperation);
        }