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

西安开发网站建设淮北做网站公司

西安开发网站建设,淮北做网站公司,php网站开发实例教程代码,企业信息系统有哪些文章目录 前言代码结果总结 前言 本文章尝试使用go实现“原型”。 代码 package mainimport (fmt )// 不同原型标志枚举 type Type intconst (PROTOTYPE_1 Type iotaPROTOTYPE_2 )// 原型接口 type IPrototype interface {Clone() IPrototypeMethod(value int)P… 文章目录 前言代码结果总结 前言 本文章尝试使用go实现“原型”。 代码 package mainimport (fmt )// 不同原型标志枚举 type Type intconst (PROTOTYPE_1 Type iotaPROTOTYPE_2 )// 原型接口 type IPrototype interface {Clone() IPrototypeMethod(value int)Print() }// 具体原型1 type ConcretePrototype1 struct {name stringvalue int }// 构造函数 func NewConcretePrototype1ByFields(name string, value int) *ConcretePrototype1 {return ConcretePrototype1{name,value,} }func NewConcretePrototype1ByObject(cp *ConcretePrototype1) *ConcretePrototype1 {return ConcretePrototype1{name: cp.name,value: cp.value,} }// 接口方法 func (cp *ConcretePrototype1) Clone() IPrototype {return NewConcretePrototype1ByObject(cp) }func (cp *ConcretePrototype1) Method(value int) {cp.value value }func (cp *ConcretePrototype1) Print() {fmt.Println(Call Method1 from , cp.name, with field : , cp.value) }// 具体原型2 type ConcretePrototype2 struct {name stringvalue int }// 构造函数 func NewConcretePrototype2ByFields(name string, value int) *ConcretePrototype2 {return ConcretePrototype2{name,value,} }func NewConcretePrototype2ByObject(cp *ConcretePrototype2) *ConcretePrototype2 {return ConcretePrototype2{name: cp.name,value: cp.value,} }// 接口方法 func (cp *ConcretePrototype2) Clone() IPrototype {return NewConcretePrototype2ByObject(cp) }func (cp *ConcretePrototype2) Method(value int) {cp.value value }func (cp *ConcretePrototype2) Print() {fmt.Println(Call Method2 from , cp.name, with field : , cp.value) }// 原型工厂 type PrototypeFactory struct {prototypes map[Type]IPrototype }func NewPrototypeFactory() *PrototypeFactory {return PrototypeFactory{prototypes: map[Type]IPrototype{PROTOTYPE_1: NewConcretePrototype1ByFields(PROTOTYPE_1 , 1),PROTOTYPE_2: NewConcretePrototype2ByFields(PROTOTYPE_2 , 2),},} }func (p *PrototypeFactory) CreatePrototype(t Type) IPrototype {return p.prototypes[t].Clone() }// 客户端代码 func clientCode(p *PrototypeFactory) {fmt.Println(Lets create a Prototype 1)prototype1 : p.CreatePrototype(PROTOTYPE_1)prototype2 : p.CreatePrototype(PROTOTYPE_1)prototype1.Method(3)prototype2.Method(4)prototype1.Print()prototype2.Print()fmt.Println()fmt.Println(Lets create a Prototype 2)prototype1 p.CreatePrototype(PROTOTYPE_2)prototype2 p.CreatePrototype(PROTOTYPE_2)prototype1.Method(5)prototype2.Method(6)prototype1.Print()prototype2.Print() }func main() {clientCode(NewPrototypeFactory()) }结果 Lets create a Prototype 1 Call Method1 from PROTOTYPE_1 with field : 3 Call Method1 from PROTOTYPE_1 with field : 4Lets create a Prototype 2 Call Method2 from PROTOTYPE_2 with field : 5 Call Method2 from PROTOTYPE_2 with field : 6总结 新人设计模式理解望大家多多指点。
http://www.hkea.cn/news/14528381/

相关文章:

  • sae 企业网站美食网站的设计与制作
  • 最早做淘宝返利的网站专业的集团网站设计网络
  • 东莞网站建设 包装材料学习网站建设优化
  • 网站创建多少钱长沙seo就选智优营家
  • 合肥网站建设服务平台杭州哪家公司做网站比较好
  • 网站建设网站系统选择网站建设素材图片
  • title:网站建设公司实力河南海华工程建设监理公司网站
  • 网站里做任务现在做网站建设的公司多么
  • 一般课程网站要怎么做宁波建网站推荐
  • 建设外贸商城网站制作自适应网站模板企业
  • wordpress建的网站打开太慢游戏公司做网站
  • 企业网站建设专业公司淘宝关键词排名查询
  • 通信工程网站建设wordpress 加载慢
  • 南京电商网站设计公司网店的运营模式有哪些
  • 搜索网站有哪几个线上职业技能培训平台
  • 织梦做的网站老是被黑怎么把百度放到网站上
  • wordpress 输出文章标签厦门网站流量优化价格
  • 网站建立定位企划wordpress微信qq登陆
  • 企业网站如何进行定位在线生成网页工具
  • 郴州住房和城乡建设部网站如何查找网站死链
  • 做新闻h5网站企业网站用织梦好吗
  • php mysql 网站模板扬州招标工程建设信息网
  • 网站建设讠金手指科杰南昌专业做网站
  • 江苏省和城乡建设门户网站如何查看网站的空间
  • wordpress怎么建设网站企业网盘价格
  • 电商网站建设是做什么的公主岭市住房和城乡建设局网站
  • 建设部网站注册师设计页面图片
  • 网上做期末试卷的网站网上国网app
  • 绿色模板网站小程序代理商怎么赚钱
  • 如何在网站上推广自己的链接wordpress文章无法中文版