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

西安开发网站建设住建局哪个科室最吃香

西安开发网站建设,住建局哪个科室最吃香,seo网站制作优化,论坛类网站搭建文章目录 前言代码结果总结 前言 本文章尝试使用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("Let's 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("Let's 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())
}

结果

Let's create a Prototype 1
Call Method1 from  PROTOTYPE_1   with field :  3
Call Method1 from  PROTOTYPE_1   with field :  4Let's create a Prototype 2
Call Method2 from  PROTOTYPE_2   with field :  5
Call Method2 from  PROTOTYPE_2   with field :  6

总结

新人设计模式理解,望大家多多指点。

http://www.15wanjia.com/news/187207.html

相关文章:

  • 辽宁城乡建设网站郑州做网站齿轮
  • 报班学网站开发价格泸州市住房与城乡建设局网站
  • 上海集酷网站网站需求表格
  • 怎样建设美食网站拖拽式建站源码
  • 三河市城乡建设局网站蒙阴做网站
  • 网站基础建设英文网站建设发布教程
  • 做家教网站怎么样手机端网站设计尺寸
  • 徐州企业网站建设photoshop破解版
  • 手机触屏版网站开发官方网站建设银行年利息是多少
  • 设计公司网站图90设计官网电脑版
  • 网站白名单 是什么海西州电子商务网站建设公司
  • 婚纱网站布局ppt怎么做wordpress 内容页面
  • 网站的优化方案佳木斯seo
  • 做医院网站及微信公众号价格国内做的比较好的二手网站
  • 免费网站空间免费主机中国建设布网站
  • 申请网站建设app外包接活
  • 买空间送网站模板商标设计网站主要提供哪些服务
  • 作文素材网站人力外包项目外包
  • 外贸网站用什么字体优化搜索引擎
  • 怎么做蛋糕页面seo是什么意思
  • 东莞网站建设东莞哪些网站可以做微课
  • 网站建设导航栏设计长沙优质营销网站建设设计
  • 深圳网站设计技术php做网站导购
  • 企业网站备案好不好站长工具ip地址
  • 高德地图看不了国外手机优化什么意思
  • 扶风网站开发宁夏做网站的
  • 千岛湖建设集团有限公司网站域名解析网站建设
  • 做动画的网站有哪些定制类做网站多少钱
  • 网站首页代码模板云南昆明最新消息
  • 网站开发 评价linux网站建设