设计模式-生成者模式之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 模式相比生成子类更为灵活. 装饰者模式是一种结构式模式 ...
随机推荐
- 1_Utilities__bandwidthTest
使用三种模式(QUICK_MODE,RANGE_MODE,SHMOO_MODE),测试三种拷贝情况下的显存带宽(HostToDevice,DeviceToHost,DeviceToDevice) ▶ ...
- zabbix监控windows系统CPU使用率
参考网站:https://blog.csdn.net/reblue520/article/details/76287113 Zabbix 自带的模块没有 CPU 使用率(百分比)这个监控项,我们可以通 ...
- java 项目中类找不到异常解决办法
最后点击Apply and Close就可以了
- as3 声明变量
var a:int=0, b, c:Number=2; trace(a,b,c) /* 0 undefined 2 */ var a:int, b:uint, c:Number; var d:Stri ...
- libcurl 支持openssl 但不能访问https
重新编译了libcurl 去访问https 地址还是不能访问 从网上找到了解决方案: curl有两种方式使用https : 1. 设定为不验证证书和HOST code = curl_easy_seto ...
- WebConfig配置讲解
http://www.cnblogs.com/cyq1162/archive/2006/11/16/562690.html sqlserver配置数据库连接字符串时需分2种情况 windows 和 s ...
- U3D游戏运行时资源是如何从AB中加载出来的
以安卓为例 1,游戏启动,自定义版本管理器去安卓的持久化目录下查找我们自定久的版本管理文件 rep.db,若该文件不存在,说明这是游戏第一次启动,于是就把streammingAssets下的LUA文件 ...
- clamav杀毒软件的安装
Linux Unix.Trojan.Elknot (Linux.BackDoor.Gates.5)木马清理 此恶意软件结合了传统后门程序和DDoS攻击木马的功能 前两天性能测试服务器被种马,cpu一直 ...
- Solving SharePoint Server 2010 - 503. The service is unavailable, After installation
Installed: SharePoint Server 2010 for Internet Enterprise Beta (x64) On: Windows Server 2008 Standar ...
- Haddop SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: process01: process01: unknown error
SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: process01: process01: unknown ...