一、简单工厂模式

@#

public class Operation  //基类
    {private double _numberA = 0;private double _numberB = 0;public double NumberA{get{ return _numberA; }set{_numberA = value;}}public double NumberB{get{ return _numberB; }set{_numberB = value;}}public virtual double GetResult(){double result = 0;return result;}}

##

    class OperationAdd:Operation    //加法类
    {public override double GetResult(){double result = 0;result = NumberA + NumberB;return result;}}class OperationSub:Operation    //减法类
    {public override double GetResult(){double result = 0;result = NumberA - NumberB;return result;}}

##

public class OperationFactory   //工厂类
    {public static Operation CreateOperate(string operate){Operation oper = null;switch(operate){case "+":oper = new OperationAdd();break;case "-":oper = new OperationSub();break;                  }return oper;}}

##

    class Program   //前台代码
    {static void Main(string[] args) {Operation oper = OperationFactory.CreateOperate("+");oper.NumberA = 20;oper.NumberB = 80;double result = oper.GetResult();Console.WriteLine(result);}}

 

转载于:https://www.cnblogs.com/tinaluo/p/6908182.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541309.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

软件生命周期模型及其类型

A life cycle model is also known as a process model. As the name suggests, the software life cycle model (or the software process model) gives us a pictorial representation of the entire software development process. 生命周期模型也称为过程模型 。 顾名思义&…

linux查看磁盘io带宽,[Linux] 磁盘IO性能查看和优化以及iostat命令

iostat命令:%user:CPU处在用户模式下的时间百分比。%nice:CPU处在带NICE值的用户模式下的时间百分比。%system:CPU处在系统模式下的时间百分比。%iowait:CPU等待输入输出完成时间的百分比。%steal:管理程序维护另一个虚…

Jsoup 数据修改

2019独角兽企业重金招聘Python工程师标准>>> 1 设置属性的值 在解析一个Document之后可能想修改其中的某些属性值,然后再保存到磁盘或都输出到前台页面。 可以使用属性设置方法 Element.attr(String key, String value), 和 Elements.attr(String key, S…

软件静态架构 软件组件图_组件图| 软件工程

软件静态架构 软件组件图什么是组件图? (What is Component Diagram?) A Component Diagram breaks down the real system under development into different heights of working. Every component is reactive for the main aim in the entire system and only re…

如何卸载非linux系统分区,如何卸载Linux系统分区?卸载Linux系统分区的方法-站长资讯中心...

系统为windows xp sp2和redhat as 5双系统,其中linux系统后安装的在D盘,华彩软件站www.huacolor.com小编今天发现硬盘不够用了,想干掉linux分区,在虚拟机中用linux。就在windows的磁盘管理(命令为:diskmgmt)下删除linux分区&#…

顺序结构复习

复习一些易错知识点还有习题 目录 可能不熟悉的知识点 逻辑表达式的求解 if,else的配队 条件运算符 运算符优先级的问题 switch的使用 goto和if构成的循环 例题讲解 1 2 3 4 ​编辑 5 ​编辑 6赋值 ​编辑 7 可能不熟悉的知识点 逻辑表达式的求解 如果…

模板模式(部分方法延迟到子类实现)

项目中,用到了抽象类作为父类,有部分实现。 提供了了模板方法作为子类公共方法,模板方法中调用了抽象类的抽象方法和部分非抽象方法。 执行代码时,发现模板方法调用了抽象类的抽象方法,当时比较好奇,后来发…

ruby 集合 分组_在Ruby中找到两个集合之间的区别

ruby 集合 分组Finding differences simply means that finding elements that are uncommon between two sets as well as are only present in the first set. We can find this, with the help of a – operator. You can also consider the objective as to find the uniqu…

怎样在linux卸载java,卸载linux自带java,linux自带java

卸载linux自带java,linux自带java第一步:rpm查询java安装包名称[rootlocalhost java]# rpm -qa | grep javajava-1.7.0-openjdk-headless-1.7.0.51-2.4.5.5.el7.x86_64tzdata-java-2014b-1.el7.noarchpython-javapackages-3.4.1-5.el7.noarchjava-1.7.0-…

Swift iOS : 内存管理

Swift是自动管理内存的。这意味着,你不需要主动释放内存。 比如Foo内包含的Bar,可以随同Foo一起被释放: import UIKit UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {var window : UIWindow?func application(…

python实现接口_Python | 使用类实现接口

python实现接口In this program, we are implementing the concept of Interface using class. Here, Class Shape worked as Interface. In Interface all methods must be non-implemented it must be implemented in child class unlike abstract class, where we can have …

linux lp 打印中文,Linux基础命令---lp打印文件

lplp指令用来打印文件,也可以修改存在的打印任务。使用该指令可以指定打印的页码、副本等。此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、Fedora、openSUSE、SUSE。1、语法lp [ -E ] [ -U username ] [ -c ] [ -d destination[/instance] ] [ -h…

【转载】浏览器缓存详解:expires cache-control last-modified

下面的内容展示了一个常见的 Response Headers,这些 Headers 要求客户端最多缓存 3600 秒,也给出了一个 pub1259380237;gz 的校验值。 HTTP/1.x 200 OK Transfer-Encoding: chunked Date: Sat, 28 Nov 2009 04:36:25 GMT Server: LiteSpeed Connection: …

ctype函数_PHP ctype_xdigit()函数与示例

ctype函数PHP ctype_xdigit()函数 (PHP ctype_xdigit() function) ctype_xdigit() function is a character type (CType) function in PHP, it is used to check whether a given string contains hexadecimal digits or not. ctype_xdigit()函数是PHP中的字符类型(CType)函数…

linux ldd运行不成功,Linux_Linux:Ldd命令介绍及使用方法,1、首先ldd不是一个可执行程序 - phpStudy...

Linux:Ldd命令介绍及使用方法1、首先ldd不是一个可执行程序,而只是一个shell脚本2、ldd能够显示可执行模块的dependency,其原理是通过设置一系列的环境变量,如下:LD_TRACE_LOADED_OBJECTS、LD_WARN、LD_BIND_NOW、LD_L…

开发原生的 Google 眼镜应用 【已翻译100%】(2/2)

使用传感器 Glass没有键盘或触摸屏,但仍然具有移动设备所有的标准的传感器。你可以使用标准的传感器组件来访问这些传感器。 定位和GPS Glass内置有GPS。TLocationSensor具有一个OnLocationChanged事件,这一事件在GPS组件被激活时产生,在有除…

linux下php的安装,Linux下PHP安装

1 下载php源码安装包 个人是php-5.6.30.tar.gzphp2 解压文件mysqltar -zxvf php-5.6.30.tar.gznginx3 编译安装sqlcd php-5.6.30api建立www用户和www用户组curlgroupadd wwwsocketuseradd -g www wwwphp-fpm在编译以前先把依赖包都装上urlyum install curl curl-develyum inst…

PHP array_filter()函数与示例

PHP array_filter()函数 (PHP array_filter() Function) array_filter() function is used to apply a filter on array elements based on the function and returns the array with filtered elements, it accepts an array to be checked and a callback function. The call…

微软宣布以 262 亿美元现金收购 LinkedIn

北京时间6月13日20:45(美国当地时间6月13日上午8:45),微软(Nasdaq: MSFT)和LinkedIn(领英,NYSE: LNKD)对外宣布,双方达成协议,微软宣布将以每股196美元、总价262亿美元的价格收购LinkedIn,由现金…

linux vim 快速定位位置,vim快速移动定位的一些操作命令

很多时候你在编辑文件时移动光标都会花很长时间,这样就无法高效的编辑了,要想达到高效编辑最好能够将光标马上定位到你需要的位置,vim就是可以满足你这样需求的一款编辑器,本节就要讲一下vim快速移动定位的一些操作命令。下面的操…