当前位置: 首页 > news >正文

养生类网站源码一件代发货源app

养生类网站源码,一件代发货源app,企业门户网站建设行情,网站信息维护建造者模式(Builder Pattern),也被称为生成器模式,是一种对象构建模式,旨在将复杂对象的构建过程与表示分离,使得同样的构建过程可以创建不同的表示。这种模式特别适用于构建具有多个组成部分的复杂对象&am…

建造者模式(Builder Pattern),也被称为生成器模式,是一种对象构建模式,旨在将复杂对象的构建过程与表示分离,使得同样的构建过程可以创建不同的表示。这种模式特别适用于构建具有多个组成部分的复杂对象,且这些组成部分的创建和组装方式相对独立。

public class BuilderPatternTest
{public void Main(){var director = new Director();//指挥者1var director1 = new Director1();//指挥者2var desktopBuilder = new DesktopBuilder();//建造者1var desktopBuilder2 = new DesktopBuilder2();//建造者2//第一台电脑,使用指挥者1,使用建造者1var computer1 = director.Construct(desktopBuilder);Console.WriteLine(computer1.ToString());//第二台电脑,使用指挥者2,使用建造者2var computer2 = director1.Construct(desktopBuilder);Console.WriteLine(computer2.ToString());//第三台电脑,使用指挥者1,使用建造者2var computer3 = director.Construct(desktopBuilder2);Console.WriteLine(computer3.ToString());//第四台电脑,使用建造者1,不使用指挥者var computer4 = new DesktopBuilder().SetType("平板电脑").SetRam(256).SetProcessor("i13212").Build();Console.WriteLine(computer4.ToString());}
}// 定义产品类
public class Computer
{public string Type { get; }public bool IsGraphicsCardIncluded { get; }public int Ram { get; }public string Processor { get; }public Computer(string type, bool isGraphicsCardIncluded, int ram, string processor){Type = type;IsGraphicsCardIncluded = isGraphicsCardIncluded;Ram = ram;Processor = processor;}public override string ToString(){return $"Type: {Type}, Graphics Card: {IsGraphicsCardIncluded}, RAM: {Ram}GB, Processor: {Processor}";}
}// 抽象建造者
// 也可以使用接口实现抽象建造者
// 方法中返回自身,以便链式调用
public abstract class Builder
{protected string Type;protected bool IsGraphicsCardIncluded;protected int Ram;protected string Processor;public abstract Computer Build();public virtual Builder SetType(string type){return this;}public virtual Builder SetGraphicsCard(bool isGraphicsCardIncluded){return this;}public virtual Builder SetRam(int ram){return this;}public virtual Builder SetProcessor(string processor){return this;}
}// 具体建造者
public class DesktopBuilder : Builder
{public override Computer Build(){return new Computer(Type, IsGraphicsCardIncluded, Ram, Processor);}public override DesktopBuilder SetType(string type){Type = type;return this;}public override DesktopBuilder SetGraphicsCard(bool isGraphicsCardIncluded){IsGraphicsCardIncluded = isGraphicsCardIncluded;return this;}public override DesktopBuilder SetRam(int ram){Ram = ram;return this;}public override DesktopBuilder SetProcessor(string processor){Processor = processor;return this;}
}public class DesktopBuilder2 : Builder
{public override Computer Build(){return new Computer(Type, IsGraphicsCardIncluded, Ram, Processor);}public override DesktopBuilder2 SetType(string type){Type = type;return this;}public override DesktopBuilder2 SetGraphicsCard(bool isGraphicsCardIncluded){IsGraphicsCardIncluded = isGraphicsCardIncluded;return this;}public override DesktopBuilder2 SetRam(int ram){Ram = ram;return this;}
}// 导演类
public class Director
{public Computer Construct(Builder builder){builder.SetType("台式电脑");builder.SetGraphicsCard(true);builder.SetRam(16);builder.SetProcessor("i7");return builder.Build();}
}public class Director1
{public Computer Construct(Builder builder){builder.SetType("笔记本电脑");builder.SetGraphicsCard(true);builder.SetRam(128);builder.SetProcessor("i1000");return builder.Build();}
}

http://www.yayakq.cn/news/830900/

相关文章:

  • 做网站电子版报价模板一站式+wordpress
  • 男女做网站互联网行业特点
  • 郑州网站制作报价用wordpress搭建
  • 宁波网站建设外包做网站支付系统
  • flash 好的网站企业信息公开网站
  • 北京公司网站设计价格2008 iis 添加 网站 权限设置
  • php网站开发用什么软件性病医院网站优化服务商
  • 如何更改 网站 关键词制作一个简单的网站
  • 即墨区建设局网站网站如何吸引
  • 怎么做简单的网站首页网站的支付接口对接怎么做
  • 网站建设与管理课后作业答案百度上做优化一年多少钱
  • 哪个网站是可以做书的住房和城乡建设部网站查询
  • 美丽寮步网站建设台州小型网站建设
  • 网站开发阶段网站空间续费多钱一年
  • 淘客做的领券网站网站开发外包维护合同范本
  • 网站开发设计有限公司seo云优化软件破解版
  • 西安网站网络营销淘宝店铺去哪里买
  • 潍坊免费模板建站深圳 网站开发公司
  • 中国免费企业建站如何做网站走查
  • 最便宜买机票网站建设马鞍山网站seo
  • 深圳福田网站制作中国十大搜索引擎排名最新
  • 外文网站制作深圳分销网站设计价格
  • 青海城乡建设厅网站 官网服务网站排名咨询
  • 企业建网站服务郑州网站外包
  • 视频点播网站开发教程推广公众号的9种方法
  • 免费网站模板制作软件定制开发公司地址
  • 仿微博网站模板境外电商网站建设
  • 鄂州网站设计制作公司手表网站免费设计
  • 镇网站制作价格seo免费教程
  • 各人可做的外贸网站平舆专业网站建设