设计模式-生成者模式之c#代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BuilderModel
{
public class Bike
{
private int wheels;
public int Wheels { get { return wheels; } set { wheels = value; } }
private int frams;
public int Frams { get { return frams; } set { frams = value; } }
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BuilderModel
{ public abstract class BuilderBike
{ public abstract void BuilWheels(int wheeels); public abstract void Buildframs(int frams);
public abstract Bike getBike();
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BuilderModel
{
public class ConsBike:BuilderBike
{
Bike bike = new Bike();
public override Bike getBike()
{
return bike;
}
public override void BuilWheels(int wheels)
{
bike.Wheels = wheels;
}
public override void Buildframs(int frams)
{
bike.Frams = frams;
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BuilderModel
{
public class DireBike
{
public void CreateBike(BuilderBike buildBike)
{
buildBike.Buildframs(1);
buildBike.BuilWheels(2);
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace BuilderModel
{
class Program
{
static void Main(string[] args)
{ BuilderBike buildBike = new ConsBike();
DireBike dirBike = new DireBike();
dirBike.CreateBike(buildBike);
Bike bike= buildBike.getBike();
Console.WriteLine("自行车的轮自有wheels="+bike.Wheels+"个"+"\t"+"架子frams="+bike.Frams+"个");
Console.ReadKey();
}
}
}
设计模式-生成者模式之c#代码的更多相关文章
- 设计模式学习--组合模式,c++代码
下面是组合模式的UML类图: <span style="font-family:Microsoft YaHei;font-size:18px;"><span st ...
- js设计模式——1.代理模式
js设计模式——1.代理模式 以下是代码示例 /*js设计模式——代理模式*/ class ReadImg { constructor(fileName) { this.fileName = file ...
- python设计模式之模板模式
python设计模式之模板模式 编写优秀代码的一个要素是避免冗余.在面向对象编程中,方法和函数是我们用来避免编写冗余代码的重要工具. 现实中,我们没法始终写出100%通用的代码.许多算法都有一些(但并 ...
- js设计模式——5.状态模式
js设计模式——5.状态模式 代码演示 /*js设计模式——状态模式*/ // 状态(红灯,黄灯,绿灯) class State { constructor(color) { this.color = ...
- 设计模式之策略模式(iOS开发,代码用Objective-C展示)
在实际开发过程中,app需求都是由产品那边给出,往往是他给出第一版功能,我们写好代码后,会相应的给出第二版.第三版功能,而这些功能是在实际使用中,根据用户需求而不断增加的.如果在编码之初,我们并未认识 ...
- 设计模式入门,策略模式,c++代码实现
// test01.cpp : Defines the entry point for the console application.////第一章,设计模式入门,策略模式#include &quo ...
- 每天一个设计模式-2 外观模式(Facade)
每天一个设计模式-2 外观模式(Facade) 1.生活中的示例 客户想要购买一台电脑,一般有两种方法: 1.自己DIY,客户需要知道组成电脑的所有电子器件,并且需要熟悉那些配件,对客户要求较高. ...
- 设计模式——抽象工厂模式及java实现
设计模式--抽象工厂模式及java实现 设计模式在大型软件工程中很重要,软件工程中采用了优秀的设计模式有利于代码维护,方便日后更改和添加功能. 设计模式有很多,而且也随着时间在不断增多,其中最著名的是 ...
- Java设计模式——装饰者模式
JAVA 设计模式 装饰者模式 用途 装饰者模式 (Decorator) 动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator 模式相比生成子类更为灵活. 装饰者模式是一种结构式模式 ...
随机推荐
- MYSQL体系结构-来自期刊
MySQL三层体系结构 |-----------------------------------------------------------------------------------| | ...
- OpenACC 绘制曼德勃罗集
▶ 书上第四章,用一系列步骤优化曼德勃罗集的计算过程. ● 代码 // constants.h ; ; ; ; const double xmin=-1.7; ; const double ymin= ...
- Python--001
C 和 Python.Java.C#等 C语言: 代码编译得到 机器码 ,机器码在处理器上直接执行,每一条指令控制CPU工作 其他语言: 代码编译得到 字节码 ,虚拟机执行字节码并转换成机器码再后在处 ...
- Code First use dotConnect for MySQL
http://www.dotblogs.com.tw/yc421206/archive/2014/03/24/144507.aspx dotConnect for MySQL 是一家強大的 3rd C ...
- spring boot 整合MongoDB
参考 https://www.cnblogs.com/nbfujx/p/7999171.html
- Linux下方便的块设备查看工具lsblk
之前在Linux下看有什么块设备,通常都用fdisk什么的或者直接ls /dev/ 去看很不方便. 这个工具属于util-linux-ng包,在RHEL 6.1上是安装好的啦,直接用就好. ubunt ...
- Rust语言学习笔记(4)
Variables and Mutability(变量和可变性) 变量声明有三种:不变量(运行期的常量),变量以及(编译期的)常量. 变量可以重复绑定,后声明的变量覆盖前面声明的同名变量,重复绑定时可 ...
- TortoiseGit 使用 HTTP 方式每次 PUSH 无需输入密码的方法
由于 BitBucket 被墙,导致使用时只能用HTTPS代理的方式,但TortoiseGit貌似没有记忆密码的功能,以至于每次push时都要求输入密码,很是麻烦!在网上搜到的保存密码的方式也有点笨. ...
- Delphi 动态数组合并
TIntArray = array of Integer; function MergeArray(const ArrayA, ArrayB: TIntArray): TIntArray; var i ...
- Numpy随机数
Numpy随机数 np.random随机数子库 1: 基本函数 .rand(d0,d1,..dn):创建d0-dn维度的随机数数组,浮点数,范围从0-1,均匀分布 .randn(d0,d1,..dn) ...