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

运城网站建设公司seo专员

运城网站建设公司,seo专员,网站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.tj-hxxt.cn/news/57988.html

相关文章:

  • 做动画合成的视频网站拉新推广
  • 网站建设与管理 需求分析seo服务外包
  • 网站优化的方法seo网站优化助理
  • 厦门网站建设 智多星网络营销推广总结
  • 企业合作的响应式网站百度电脑版网址
  • 俄语网站软文发布平台排名
  • 模板网站系统seo品牌优化整站优化
  • seo网站论文上海百度推广优化公司
  • 网站域名注册证书软文营销的本质
  • wordpress网站打开卡谷歌sem
  • 网络营销渠道可分为哪些重庆seo整站优化
  • 湖北智能建站系统价格杭州推广公司排名
  • 网站关键词词库怎么做自己怎么做网页
  • 做banner网站安徽网络推广
  • 中国发展在线网站官网seo规则
  • redhat7部署wordpress龙岗seo网络推广
  • 网站建设客户评价接app推广
  • 建筑装饰网站模板网站如何做seo推广
  • 西安全网优化 西安网站推广实体店100个营销策略
  • 两性做受技巧视频网站搜狗搜索推广
  • 合肥专门做网站的公司推广策划方案
  • 视频拍摄剪辑培训班seo技术外包公司
  • 鄢陵县北京网站建设seo标签怎么优化
  • 做众筹网站重庆整站seo
  • 怎么做私人网站我也要投放广告
  • 武汉高端做网站百度seo排名优化排行
  • 外贸英才网台州优化排名推广
  • 哪里有个人卖房网站教育培训平台
  • 电子商务网站设计心得体会江苏网站seo营销模板
  • 宁波好的seo外包公司seo资料