Design Pattern——Factory_DP
namespace TEST
{
//用于生成一个对应的操作类,这个工厂只是用来产生操作类的,不做其他只用
public class Factory
{
public Operate GetOpetration(string mark)
{
switch(mark)
{
case "+":
return new OperateAdd();
break;
case "-":
return new OperateSub();
break;
case "*":
return new OperateMultiply();
break;
case "/":
return new OperateDivision();
break;
default:
return null;
break;
}
}
}
//这个类是用来执行相关的操作的
public abstract class Operate
{
public double operateTwo { get; set; }
public double operateOne { get; set; }
public abstract string Opetration();
}
public class OperateAdd:Operate
{
public override string Opetration()
{
return Convert.ToString(base.operateOne + base.operateTwo);
}
}
public class OperateSub : Operate
{
public override string Opetration()
{
return Convert.ToString(this.operateOne - this.operateTwo);
}
}
public class OperateMultiply : Operate
{
public override string Opetration()
{
return Convert.ToString(this.operateOne*this.operateTwo);
}
}
public class OperateDivision : Operate
{
public override string Opetration()
{
if (this.operateTwo != )
return Convert.ToString(this.operateOne / this.operateTwo);
else
return "input error";
}
}
class Program
{
static void Main(string[] args)
{
try
{
double num1=Convert.ToDouble( Console.ReadLine());
double num2 =Convert.ToDouble( Console.ReadLine());
string op = Convert.ToString(Console.ReadLine());
var factory = new Factory();
var Opetration = factory.GetOpetration(op);
Opetration.operateOne = num1;
Opetration.operateTwo = num2;
Console.WriteLine(Opetration.Opetration()); Console.Read(); Console.Read();
}
catch (Exception ex)
{
Console.WriteLine("程序出错");
} }
}
}
Design Pattern——Factory_DP的更多相关文章
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- [转]Design Pattern Interview Questions - Part 2
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...
- [转]Design Pattern Interview Questions - Part 3
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- design pattern
1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor
- Design Pattern: Observer Pattern
1. Brief 一直对Observer Pattern和Pub/Sub Pattern有所混淆,下面打算通过这两篇Blog来梳理这两种模式.若有纰漏请大家指正. 2. Use Case 首先我们来面 ...
- Scalaz(10)- Monad:就是一种函数式编程模式-a design pattern
Monad typeclass不是一种类型,而是一种程序设计模式(design pattern),是泛函编程中最重要的编程概念,因而很多行内人把FP又称为Monadic Programming.这其中 ...
随机推荐
- springMVC之数据传递
在前面介绍过从controller中向页面中传数据,可以通过HttpServletRequest进行setAttribute可以将数据放入request中.并且可以在jsp页面使用el表达式获取数据. ...
- CoreCLR文档翻译 - GC的设计
此文档来源于CoreCLR的BOTR(The Book of the Runtime), 点击打开原文 一切著作权归微软公司所有 GC的设计 作者: Maoni Stephens (@maoni0) ...
- ASP.NET中的C#基础知识
ASP.NET中的C#基础知识 说明:asp.net作为一种开发框架现在已经广为应用,其开发的基础除了前端的html.css.JavaScript等后端最重要的语言支持还是C#,下面将主要用到的基础知 ...
- Python高手之路【十二】面向对象设计模式
单例模式 单例,顾名思义单个实例. class Person: __instance = None def __init__(self): pass @staticmethod def getInst ...
- iOS开发-OC语言 (七)继承、多态、类别
继承.多态.类别 学习目标 1.继承的含义 2.父类子类的别称 3.字段和消息的继承 4.重写和重写消息的调用 5.多态 6.类别(Category) ======================== ...
- eclipse安装
1.下载破解版本 地址:http://www.oyksoft.com/soft/1250.html 2.解压下载包,直接运行eclipse.exe 3.安装过程中如果遇到问题 1).如果遇到erro ...
- shell 字符串包含
转自:Shell判断字符串包含关系的几种方法 现在每次分析网站日志的时候都需要判断百度蜘蛛是不是真实的蜘蛛,nslookup之后需要判断结果中是否包含"baidu"字符串 以下给出 ...
- 汇农PC个人中心总结
1. 技巧总结 1. 使用 padding 编写灵活的 登录 | 注册, '|' 竖线, 参考: http://www.imooc.com/learn/710 font-size: 0; border ...
- iOS 水波效果
将水波效果放在子视图上,主控制器只负责加载 #import "WaveProgress.h" @interface WaveProgress () @property (nonat ...
- Apache server for win解压版的安装与配置
下载地址: Apache 2.4.16 Win64位:VC14:http://www.apachelounge.com/download/VC14/binaries/httpd-2.4.16-win6 ...