01 简单工厂模式/OperationLibrary/OperationFactory.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*
* ==============================================================================
*
* File name: OperationFactory
* Description: 
*
* Version: 1.0
* Created: 2015-07-07 11:00:52
*
* Author: Your name
* Company: Your company name
*
* ==============================================================================
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OperationLibrary
{
    /// <summary>
    /// 运算工厂类,(到底要实例化谁(创建对象))
    /// 缺点:包含了必要的 判断逻辑,违反开闭
    /// </summary>
    public class OperationFactory
    {
        public static Operation createOperation(string operate)
        {
            Operation oper = null;  //父类对象,子类也适用(里氏替换)
            switch (operate)
            {
                case "+":
                    {
                        oper = new OperationAdd(); //创建加法类
                        break;
                    }
                case "-":
                    {
                        oper = new OperationSub();
                        break;
                    }
                case "*":
                    {
                        oper = new OpertionMul();
                        break;
                    }
                case "/":
                    {
                        oper = new OperationDiv();
                        break;
                    }
                case "sqr":
                    {
                        oper = new OperationSqr();
                        break;
                    }
                case "sqrt":
                    {
后面还有 15 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。