![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
xinxin100011
这个作者很懒,什么都没留下…
展开
-
工厂模式 Go例子
工厂模式,每个实例都实现接口,调用清晰 结合gorouine,实例可以并发执行相似的步骤 工作中遇到的例子 package main import ( "fmt" "golang.org/x/sync/errgroup" ) type ModuleHandler interface { //接口 foo(chan int) //channel用来传递数据 } var moduleHandlers []ModuleHandler func init() { //init收集各实例 modu原创 2021-09-10 15:39:58 · 130 阅读 · 0 评论 -
模板模式 Go例子
接口Say 父类SayAny,实现模板中通用的方法 方法DoSay(Say),封装调用模板各个方法 子类Hello,实现各自具体逻辑 package main import "fmt" type Say interface { //这里定义好模板,子类需要具有的方法 beforeSay() say() } type SayAny struct{} func (SayAny) beforeSay() { //模板实现通用的方法 fmt.Println("get up the courage .原创 2021-09-09 18:18:40 · 76 阅读 · 0 评论