自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 资源 (2)
  • 收藏
  • 关注

原创 设计模式——Go语言(Golang)版:24_迭代器模式

示例代码:package mainimport ( "fmt")//迭代器接口type Iterator interface { First() IsDone() bool Next() interface{}}//迭代的数据集type Aggregate interface { Iterator() Iterator}type Numbers struct { start, end int}//实现迭代器接口对应的功能type NumbersIterator s

2021-04-08 09:08:28 369

原创 设计模式——Go语言(Golang)版:23_访问者模式

示例代码:package mainimport "fmt"type Customer interface { Accept(visitor Visitor)}type Visitor interface { Visit(customer Customer)}//客户群type CustomerCol struct { customers []Customer}func (c *CustomerCol) Add(customer Customer) { c.custom

2021-04-08 09:08:03 484 1

原创 设计模式——Go语言(Golang)版:22_命令模式

示例代码:package mainimport "fmt"type Command interface { Execute()}type MotherBoard struct{}func (*MotherBoard) Start() { fmt.Println("系统启动中...")}func (*MotherBoard) Reboot() { fmt.Println("系统重启中...")}//====启动命令=====type StartCommand struc

2021-04-08 09:07:31 277

原创 设计模式——Go语言(Golang)版:21_备忘录模式

示例代码:package mainimport "fmt"//备忘录模式用于保存程序内部状态到外部,又不希望暴露内部状态的情形。type Memento interface{}type gameMemento struct { hp, mp int}type Game struct { hp, mp int}func (g *Game) Play(mpDelta, hpDelta int) { g.hp += hpDelta g.mp += mpDelta}func (

2021-04-08 09:07:03 256

原创 设计模式——Go语言(Golang)版:20_策略模式

示例代码:package mainimport "fmt"//支付环境type PaymentContext struct { Name ,CardId string Money int}//支付策略type PaymentStrategy interface { Pay(ctx *PaymentContext)}//支付type Payment struct { Context *PaymentContext Strategy PaymentStrategy}f

2021-04-08 09:06:30 598

原创 设计模式——Go语言(Golang)版:19_中介模式

示例代码:package mainimport ( "fmt" "strings")type CDDriver struct { Data string}func (c *CDDriver) ReadData() { //c.Data = "音乐、图片" fmt.Println("CD驱动器正在读取:", c.Data)}type CPUDriver struct { Video string Sound string}func (c *CPUDriver)

2021-04-07 09:24:26 204

原创 设计模式——Go语言(Golang)版:18_模板模式

示例代码:package mainimport "fmt"type DownLoader interface { Download(uri string)}//具体实施type implement interface { download() save()}//模板type template struct { implement uri string}func (t *template) Download(uri string) { t.uri = uri fm

2021-04-07 09:24:03 386 1

原创 设计模式——Go语言(Golang)版:17_状态模式

示例代码:package mainimport "fmt"//状态模式用于分离状态和行为。//周一 至 周日 时间之间的切换type Week interface { Today() Next(ctx *DayContext)}type DayContext struct { today Week}func (dc *DayContext)Today() { dc.today.Today() //调用父类(接口)的方法,具体实现是在对应的类(结构体)中}func

2021-04-07 09:23:35 246

原创 设计模式——Go语言(Golang)版:16_解释器模式

示例代码:package mainimport ( "fmt" "strconv" "strings")//解释器接口type Node interface { Interpret() int //解释方法}//数据节点type ValNode struct { val int}func (vn *ValNode) Interpret() int { return vn.val}//=============加法节点=============type Ad

2021-04-07 09:23:13 523

原创 设计模式——Go语言(Golang)版:15_观察者模式

示例代码:package mainimport "fmt"type Observer interface { Update(subject *Subject)}type Subject struct { observers []Observer msg string}//添加观察者func (s *Subject) Attach(o Observer) { s.observers = append(s.observers, o)}//通知信息到观察者fu

2021-04-07 09:22:44 341

原创 设计模式——Go语言(Golang)版:14_责任链模式

示例代码:package mainimport "fmt"type Manager interface { HaveRight(money int)bool //有权做 HandleFeeRequest(name string,money int)bool //处理费用请求}type RequestChain struct { Manager successor *RequestChain //后续者(链式结构,链表)}func (rc *RequestChain)HaveR

2021-04-07 09:22:22 369

原创 设计模式——Go语言(Golang)版:13_享元模式

示例代码:package mainimport "fmt"//轻量级图片type ImageFlyweight struct { data string}func (i *ImageFlyweight) Data() string { return i.data}func NewImageFlyweight(fileName string) *ImageFlyweight { d := fmt.Sprintf("image data:%s", fileName) retur

2021-04-07 09:21:51 192

原创 设计模式——Go语言(Golang)版:12_装饰器模式

示例代码:package mainimport "fmt"type Component interface { Calc() int}type ConcreteComponent struct{}func (*ConcreteComponent) Calc() int { return 0}//乘法修饰器type MulDecorator struct { Component num int}func (d *MulDecorator) Calc() int {

2021-04-07 09:21:22 375

原创 设计模式——Go语言(Golang)版:11_桥接模式

示例代码:package mainimport "fmt"//发送信息的具体实现(操作)type MessageImplementer interface { send(test, to string)}//发送SMStype MessageSMS struct{}func (*MessageSMS) send(test, to string) { fmt.Printf("SMS信息:[%v];发送到:[%v]\n", test, to)}func ViaSMS() *Mes

2021-04-07 09:20:40 278

原创 设计模式——Go语言(Golang)版:10_外观模式

示例代码:package mainimport "fmt"func NewAPI() API { return &apiImpl{ a: NewAModuleAPI(), b: NewBModuleAPI(), }}//API is facade interface of facade packagetype API interface { Test() string}//facade implementtype apiImpl struct { a A

2021-04-07 09:19:51 195

原创 设计模式——Go语言(Golang)版:09_代理模式

示例代码:package mainimport "fmt"type Subject interface { Do() string}type RealSubject struct{}func (r *RealSubject) Do() string { return "执行以太坊智能合约"}type ProxySubject struct { RealSubject money int}func (p *ProxySubject) Do() string { if

2021-04-06 17:38:29 181

原创 设计模式——Go语言(Golang)版:08_组合模式

示例代码:package mainimport "fmt"type Component interface { Parent() Component SetParent(Component) Name() string SetName(string) AddChild(Component) Print(string)}const ( LeafNode = iota CompositeNode)func NewComponent(kind int, name strin

2021-04-06 17:37:21 248

原创 设计模式——Go语言(Golang)版:07_适配器模式

示例代码:package mainimport "fmt"//================1.被适配对象================//被适配的接口type Adapter interface { SpecRequest(int, int) string}//接口载体type AdapterImpl struct{}func (ap *AdapterImpl) SpecRequest(int, int) string { return "目标对象:SpecReque

2021-04-06 17:34:41 287

原创 设计模式——Go语言(Golang)版:06_建造者模式

示例代码:package mainimport "fmt"//================1.建造者接口==============//Builder 是生成器接口type Builder interface { Part1() Part2() Part3()}//===============2.建造者对象及操作===============type Director struct { builder Builder //建造者的接口}//创建接口func N

2021-04-06 17:33:25 269

原创 设计模式——Go语言(Golang)版:05_原型模式

示例代码:package mainimport "fmt"//1.原型对象需要实现的接口type Cloneable interface { Clone() Cloneable}//2.原型对象的类type PrototypeManager struct { prototypes map[string]Cloneable}//3.原型对象操作func NewPrototypeManger() *PrototypeManager { return &Prototy

2021-04-06 17:32:08 296

原创 设计模式——Go语言(Golang)版:04_单例模式

示例代码:package mainimport ( "fmt" "sync")type SingleData struct { data interface{}}var data *SingleDatavar once sync.Once //通过该类型可以实现单例模式,虽然是多次赋值,但是只执行一次(一个对象多次实例化,但是只有一个,共享对象地址)func getInstance(i int) *SingleData { once.Do(func() { data

2021-04-06 17:28:21 245

原创 设计模式——Go语言(Golang)版:03_抽象工厂模式

示例代码:package mainimport "fmt"//OrderMainDAO 为订单主记录type OrderMainDAO interface { SaveOrderMain()}//OrderDetailDAO 为订单详情纪录type OrderDetailDAO interface { SaveOrderDetail()}//DAOFactory DAO 抽象模式工厂接口type DAOFactory interface { CreateOrderMain

2021-04-06 17:26:50 518

原创 设计模式——Go语言(Golang)版:02_工厂方法模式

示例代码:package main//==============2.工厂模式===================//Operator 是被封装的实际类接口type Operator interface { SetA(int) SetB(int) Result() int}//OperatorFactory 是工厂接口type OperatorFactory interface { Create() Operator}//OperatorBase 是Operator 接口

2021-04-06 17:25:00 402

原创 设计模式——Go语言(Golang)版:01_简单工厂模式

示例代码:package mainimport "fmt"//===============1.定义简单接口=================type SimpleAPI interface { Say(content string) string}//===============2.实现对应的接口===============//对象1type Chinese struct {}func (c *Chinese) Say(content string) string {

2021-04-06 17:22:51 469

原创 设计模式——Go语言(Golang)版

设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。从本节开始,陆续介绍设计模式,该设计模式采用Go语言编码实现。01_简单工厂模式02_工厂方法模式03_抽象工厂模式04_单例模式05_原型模式06_建筑者模式07_适配器模式08_组合模式09_代理模式10_外观模式1.

2021-04-06 17:10:52 904

go连接MySQL包

go连接MySQL包:mysql比较优秀的一个驱动是:github.com/go-sql-driver/mysql

2018-09-20

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除