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#代码的更多相关文章

  1. 设计模式学习--组合模式,c++代码

    下面是组合模式的UML类图: <span style="font-family:Microsoft YaHei;font-size:18px;"><span st ...

  2. js设计模式——1.代理模式

    js设计模式——1.代理模式 以下是代码示例 /*js设计模式——代理模式*/ class ReadImg { constructor(fileName) { this.fileName = file ...

  3. python设计模式之模板模式

    python设计模式之模板模式 编写优秀代码的一个要素是避免冗余.在面向对象编程中,方法和函数是我们用来避免编写冗余代码的重要工具. 现实中,我们没法始终写出100%通用的代码.许多算法都有一些(但并 ...

  4. js设计模式——5.状态模式

    js设计模式——5.状态模式 代码演示 /*js设计模式——状态模式*/ // 状态(红灯,黄灯,绿灯) class State { constructor(color) { this.color = ...

  5. 设计模式之策略模式(iOS开发,代码用Objective-C展示)

    在实际开发过程中,app需求都是由产品那边给出,往往是他给出第一版功能,我们写好代码后,会相应的给出第二版.第三版功能,而这些功能是在实际使用中,根据用户需求而不断增加的.如果在编码之初,我们并未认识 ...

  6. 设计模式入门,策略模式,c++代码实现

    // test01.cpp : Defines the entry point for the console application.////第一章,设计模式入门,策略模式#include &quo ...

  7. 每天一个设计模式-2 外观模式(Facade)

    每天一个设计模式-2  外观模式(Facade) 1.生活中的示例 客户想要购买一台电脑,一般有两种方法: 1.自己DIY,客户需要知道组成电脑的所有电子器件,并且需要熟悉那些配件,对客户要求较高. ...

  8. 设计模式——抽象工厂模式及java实现

    设计模式--抽象工厂模式及java实现 设计模式在大型软件工程中很重要,软件工程中采用了优秀的设计模式有利于代码维护,方便日后更改和添加功能. 设计模式有很多,而且也随着时间在不断增多,其中最著名的是 ...

  9. Java设计模式——装饰者模式

    JAVA 设计模式 装饰者模式 用途 装饰者模式 (Decorator) 动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator 模式相比生成子类更为灵活. 装饰者模式是一种结构式模式 ...

随机推荐

  1. 温故而知新-正则单词和strlen

    1 正则表达式用\b表示单词的开始和结束 \bblog\b 正则查找blog这个单词 2 关于strlen的汉字问题 在utf8格式下  strlen('汉字')=6 在gbk格式下 strlen(' ...

  2. 0_Simple__simpleSurfaceWrite

    使用表面写入函数,结合纹理引用实现图片的旋转▶ 源代码 #include <stdio.h> #include <windows.h> #include <cuda_ru ...

  3. angular 参考文档

    https://www.w3schools.com/angular/ 参考二: https://www.angular.cn/guide/reactive-forms

  4. 可视化库-seaborn-单变量绘图(第五天)

    1. sns.distplot 画直方图 import numpy as np import pandas as pd from scipy import stats, integrate impor ...

  5. as3 AIR 添加或删除ApplicationDirectory目录下文件

    AIR的文件目录静态类型有五种: File.userDirectory //指向用户文件夹 File.documentsDirectory //指向用户文档文件夹 File.desktopDirect ...

  6. Flash Builder编译的swf为什么在bin-debug下运行正常,复制到其他文件夹就不正常

    在Flash Builder/Flex Builder中,可以使用编译参数-use-network=false实现

  7. as2 fla 关于影片在时间轴的问题

    多帧上面放着没实例名而且里面内容一致的影片,主要一开始读取了,那么跳帧的时候.会自动获取当前帧上的相同内容的影片. 但如果内容不一致的影片,那么在跳帧后,不会获取当前的影片,旧的影片也无法获取.只在当 ...

  8. UI5-文档-4.34-Custom Controls

    在这一步中,我们将使用自定义控件扩展SAPUI5的功能.我们希望对详细页面上显示的产品进行评级,因此我们使用SAPUI5扩展机制创建了多个标准控件的组合,并添加了一些粘合代码以使它们能够很好地一起工作 ...

  9. webserive学习记录6-页面请求webservice

    前面都是通过JAVA代码访问webservice服务,下面将介绍通过javascript,jquery访问webservice服务并介绍过过servlet解决跨域问题的方法. 服务端 编写服务代码,解 ...

  10. The maximum column size is 767 bytes (Mysql)

     ERROR app.wsutils 419 INCRON: Error: ('HY000', '[HY000] [MySQL][ODBC 5.2(w) Driver][mysqld-5.7.7-rc ...