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. 使用Python调用动态库

    我个人在日常使用电脑时,经常需要使用Google,于是就要切换代理,基本上是一会儿切换为代理,一会儿切换成直连,老是打开internet 选项去设置,很不方便,于是我萌生了一个想法: 做一个开关,我想 ...

  2. 位运算骚操作 Part 1

    ▶ 原文标题<Bit Twiddling Hacks>,地址:https://graphics.stanford.edu/~seander/bithacks.html ▶ 额外参考资料:h ...

  3. mysql 忽略某个错误 继续执行

    执行如下存储过程: CREATE  PROCEDURE `aa`()BEGINcall RealtimeData_9035();call RealtimeData_9504();call Realti ...

  4. java的锁机制,synchronize与Lock比较

    参考:https://blog.csdn.net/dahongwudi/article/details/78201082

  5. vue-cli 3.0之跨域请求代理配置及axios路径配置

    vue-cli 3.0之跨域请求代理配置及axios路径配置 问题:在前后端分离的跨域请求中,报跨域问题 配置: vue.config.js: module.exports = { runtimeCo ...

  6. jd-eclipse反编译插件的在线安装和使用

    jd-eclipse反编译插件的在线安装和使用 JD-Eclipse是一个Eclipse平台的插件.它允许您调试所有的Java源代码,有了它,以后调试的时候ctrl键就可以一键到底啦.下面简单说说ec ...

  7. Spring Boot 入门搭建

    一.前言 Spring Boot 的设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置. 二.环境搭建 创建一个 ...

  8. select 实现多路复用IO的server_socket

    select 对程序进行同时检测,当发生响应时,数据被拷贝到内核区域,内核区通知用户程序来进行读取数据,内核区域并不知道是客户端连接,因此需要进行循环 server_socket 端 import s ...

  9. python 逐行读取文本

    f = open("foo.txt") # 返回一个文件对象line = f.readline() # 调用文件的 readline()方法while line: print li ...

  10. mysql创建定时器(event),查看定时器,打开定时器,设置定时器时间

    由于项目需要创建定时器(evevt),所以就百度了一下,发现基本都是来源于一个模板,有些功能还不全,现在自己总结一下. 注:mysql版本是从5.1开始才支持event的.如果你的版本低于5.1就先升 ...