Пример #1
0
        //简单工厂设计模式
        private static Calculator GetComputerObject(string caozuofu, double d1, double d2)
        {
            Calculator result = null;

            switch (caozuofu)
            {
            case "+": result = new JiaFaClass(d1, d2);
                break;

            case "-": result = new JianFaClass(d1, d2);
                break;

            case "*": result = new ChengFa(d1, d2);
                break;

            default:
                break;
            }

            return(result);
        }
Пример #2
0
        //简单工厂设计模式
        private static Calculator GetComputedObject(string yunSuanFu, double n1, double n2)
        {
            Calculator result = null;

            switch (yunSuanFu)
            {
            case "+":
                result = new JiaFaClass(n1, n2);
                break;

            case "-":
                result = new JianFaClass(n1, n2);
                break;

            case "*":
                result = new ChengFaClass(n1, n2);
                break;

            case "/":
                result = new ChuFaClass(n1, n2);
                break;
            }
            return(result);
        }