-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FangjieLiang
committed
Sep 13, 2022
1 parent
4c03513
commit ea1f5b3
Showing
23 changed files
with
96 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: go | ||
go: | ||
- 1.x | ||
- 1.11.x | ||
go: | ||
- 1.x | ||
- 1.11.x | ||
script: | ||
- go test -v ./... | ||
- go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# 简单工厂模式 | ||
|
||
go 语言没有构造函数一说,所以一般会定义NewXXX函数来初始化相关类。 | ||
NewXXX 函数返回接口时就是简单工厂模式,也就是说Golang的一般推荐做法就是简单工厂。 | ||
`go` 语言没有构造函数一说,所以一般会定义 `NewXXX` 函数来初始化相关类。 | ||
`NewXXX` 函数返回接口时就是简单工厂模式,也就是说 `Golang` 的一般推荐做法就是简单工厂。 | ||
|
||
在这个simplefactory包中只有API 接口和NewAPI函数为包外可见,封装了实现细节。 | ||
在这个 `simplefactory` 包中只有API 接口和 `NewAPI` 函数为包外可见,封装了实现细节。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# 外观模式 | ||
|
||
API 为facade 模块的外观接口,大部分代码使用此接口简化对facade类的访问。 | ||
`API` 为 `facade` 模块的外观接口,大部分代码使用此接口简化对 `facade` 类的访问。 | ||
|
||
facade模块同时暴露了a和b 两个Module 的NewXXX和interface,其它代码如果需要使用细节功能时可以直接调用。 | ||
`facade` 模块同时暴露了 `a` 和 `b` 两个 `Module` 的 `NewXXX` 和 `interface`,其它代码如果需要使用细节功能时可以直接调用。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
package adapter | ||
|
||
//Target 是适配的目标接口 | ||
// Target 是适配的目标接口 | ||
type Target interface { | ||
Request() string | ||
} | ||
|
||
//Adaptee 是被适配的目标接口 | ||
// Adaptee 是被适配的目标接口 | ||
type Adaptee interface { | ||
SpecificRequest() string | ||
} | ||
|
||
//NewAdaptee 是被适配接口的工厂函数 | ||
// NewAdaptee 是被适配接口的工厂函数 | ||
func NewAdaptee() Adaptee { | ||
return &adapteeImpl{} | ||
} | ||
|
||
//AdapteeImpl 是被适配的目标类 | ||
// AdapteeImpl 是被适配的目标类 | ||
type adapteeImpl struct{} | ||
|
||
//SpecificRequest 是目标类的一个方法 | ||
// SpecificRequest 是目标类的一个方法 | ||
func (*adapteeImpl) SpecificRequest() string { | ||
return "adaptee method" | ||
} | ||
|
||
//NewAdapter 是Adapter的工厂函数 | ||
// NewAdapter 是Adapter的工厂函数 | ||
func NewAdapter(adaptee Adaptee) Target { | ||
return &adapter{ | ||
Adaptee: adaptee, | ||
} | ||
} | ||
|
||
//Adapter 是转换Adaptee为Target接口的适配器 | ||
// Adapter 是转换Adaptee为Target接口的适配器 | ||
type adapter struct { | ||
Adaptee | ||
} | ||
|
||
//Request 实现Target接口 | ||
// Request 实现Target接口 | ||
func (a *adapter) Request() string { | ||
return a.SpecificRequest() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
工厂方法模式使用子类的方式延迟生成对象到子类中实现。 | ||
|
||
Go中不存在继承 所以使用匿名组合来实现 | ||
`Go` 中不存在继承 所以使用匿名组合来实现 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.