Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 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);
        }
Ejemplo n.º 5
0
        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);
        }