当前位置: 首页 > news >正文

家乡网站建设自己做一个网站需要什么

家乡网站建设,自己做一个网站需要什么,中资建筑信息平台,哪个网站开发票编程时一门技术,更是一门艺术 简单工厂模式利用面向对象方式通过继承、封装、多态把程序的耦合度降低,设计模式使得程序更加灵活,容易修改,易于复用。 下面是服务器计算器代码: 1 using System;2 using System.Collect…

编程时一门技术,更是一门艺术

简单工厂模式利用面向对象方式通过继承、封装、多态把程序的耦合度降低,设计模式使得程序更加灵活,容易修改,易于复用。

下面是服务器计算器代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace DesignModel
 8 {
 9     /// <summary>
10     /// 计算器
11     /// </summary>
12     public class Calculator   //创建一个计算器的基类可以接受两个参数,任何算法只需重写计算结果方法即可。
13     {
14         private double _numberA;
15         private double _numberB;
16 
17         public double NumberA
18         {
19             get { return this._numberA; }
20             set { this._numberA = value; }
21         }
22         public double NumberB
23         {
24             get { return this._numberB; }
25             set { this._numberB = value; }
26         }
27         public virtual double GetResult()
28         {
29             double result = 0;
30             return result;
31         }
32     }
33     /// <summary>
34     /// 加法
35     /// </summary>
36     public class Add : Calculator    //每添加一种计算方式只需添加一个计算类并重写基类方法即可
37     {
38         public override double GetResult()
39         {
40             return  NumberA + NumberB;
41         }
42     }
43     /// <summary>
44     /// 减法
45     /// </summary>
46     public class Sub : Calculator
47     {
48         public override double GetResult()
49         {
50             return NumberA + NumberB;
51         }
52     }
53 
54     /// <summary>
55     /// 计算器工厂
56     /// </summary>
57     public class CalculatorFactory
58     {
59         public static Calculator GetResult(string oper)
60         {
61             Calculator calcu = null;
62             switch (oper)
63             {
64                 case "+":
65                     calcu = new Add();
66                     break;
67                 case "-":
68                     calcu = new Sub();
69                     break;
70             }
71             return calcu;
72         }
73 
74     }
75 
76 
77 }
计算器类
 1  static void Main(string[] args)
 2         {
 3             Console.WriteLine("请输入数字A:");
 4             string numbera = Console.ReadLine();
 5             Console.WriteLine("请输入运算符:");
 6             string oper = Console.ReadLine();
 7             Console.WriteLine("请输入数字B:");
 8             string numberb = Console.ReadLine();
 9 
10             Calculator c = CalculatorFactory.GetResult(oper);
11             c.NumberA = Convert.ToDouble(numbera);
12             c.NumberB = Convert.ToDouble(numberb);
13             Console.WriteLine(string.Format("{0}{1}{2}={3}", numbera, oper, numberb, c.GetResult()));
14             Console.ReadLine();
15         }
客户端调用

基本验证没加,学习练习的同学可以自己加上

28种设计模式后续更新

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignModel
{
    /// <summary>
    /// 计算器
    /// </summary>
    public class Calculator   //创建一个计算器的基类可以接受两个参数,任何算法只需重写计算结果方法即可。
    {
        private double _numberA;
        private double _numberB;

        public double NumberA
        {
            get { return this._numberA; }
            set { this._numberA = value; }
        }
        public double NumberB
        {
            get { return this._numberB; }
            set { this._numberB = value; }
        }
        public virtual double GetResult()
        {
            double result = 0;
            return result;
        }
    }
    /// <summary>
    /// 加法
    /// </summary>
    public class Add : Calculator    //每添加一种计算方式只需添加一个计算类并重写基类方法即可
    {
        public override double GetResult()
        {
            return  NumberA + NumberB;
        }
    }
    /// <summary>
    /// 减法
    /// </summary>
    public class Sub : Calculator
    {
        public override double GetResult()
        {
            return NumberA + NumberB;
        }
    }

    /// <summary>
    /// 计算器工厂
    /// </summary>
    public class CalculatorFactory
    {
        public static Calculator GetResult(string oper)
        {
            Calculator calcu = null;
            switch (oper)
            {
                case "+":
                    calcu = new Add();
                    break;
                case "-":
                    calcu = new Sub();
                    break;
            }
            return calcu;
        }

    }


}

转载于:https://www.cnblogs.com/zhanjun/p/3854534.html

http://www.lbrq.cn/news/2458135.html

相关文章:

  • app网站建设源码搜索关键词的软件
  • 湖北标书设计制作360手机优化大师下载
  • 杭州品格网站设计优化是什么意思
  • 青岛东八区创意做网站kol合作推广
  • 网页制作软件培训机构优化网站结构一般包括
  • 如何做企业网站规划在线资源链接
  • 大型的网页设计公司关键词优化是什么工作
  • wordpress网站百度不收录外贸平台
  • 微商怎么引流推广宁波seo链接优化
  • 今日重大新闻头条财经建站优化公司
  • 成品网站 修改首页亚洲长尾关键词挖掘
  • 织梦 网站复制什么是搜索引擎竞价推广
  • 哪个网站的地图可以做分析图网站推广seo教程
  • 北京公司请做网站工资免费友情链接网页
  • 零食铺网站建设策划书网站设计模板
  • 上海市城乡住房建设厅网站希爱力的功效及副作用
  • 专业简历制作软件长沙网站seo诊断
  • 企业在公司做的网站看不到查看今日头条
  • 网站如何做关键字收录网络营销工具介绍
  • 济宁网站建设有限公司深圳最新新闻事件今天
  • 网页美工设计流程为win7优化配置的方法
  • 相城网页设计seo案例
  • 苏州网站推广找苏州梦易行今日新闻最新
  • 音乐网站建设教程楚雄今日头条新闻
  • 社联网站建设的目的广州百度推广代理公司
  • phpcms 图片网站中央常委成员名单
  • 中铁三局招聘2022关键词优化怎么弄
  • wordpress 扒站教程seo推广方法有哪些
  • 房产交易网站建设策划案店铺推广软文300字
  • 做网站的项目职责怎么写网络营销站点推广的方法
  • C++ 多线程同步机制详解:互斥锁、条件变量与原子操作
  • XCTF-crypto-幂数加密
  • [实战] 用1 PPS 驯服本地恒温晶振(OCXO/TCXO)
  • 使用全局变量访问 Qt UI 组件的方法文档
  • 【物联网】基于树莓派的物联网开发【16】——树莓派GPIO控制LED灯实验
  • 网络基础DAY18-动态路由协议基础