创建文件MMFeel.go
package memento
import "fmt"
type MMFeel struct {
Tall int
Rich int
Handsome int
}
var States []MMFeel = make([]MMFeel, 0)
var StatesLength int ...
创建文件MM.go
package strategy
import "fmt"
type MMContext struct {
Name string
Age int
paoStrategy MMStrategy
}
func NewMMContext(name string, age int, str...
创建文件CPU.go
package mediator
import "fmt"
type CPU struct {
data string
}
func (c *CPU) Process(data string) {
fmt.Println("CPU is running", data)
}
创建文件GPU.go
pack...
创建文件Downloader.go
package template
import "fmt"
type Downloader interface {
Download(url string)
}
type template struct {
implement
url string
}
type implement int...
创建文件Week.go
package state
// 每个星期行为
type Week interface {
Today()
Next(*DayContext)
}
// 星期数据结构
type DayContext struct {
today Week
}
func NewDayContext...
创建文件Node.go
package interpreter
type Node interface {
Interpreter() int
}
type ValNode struct {
val int
}
func (v *ValNode) Interpreter() int {
return v.val
}
创...
创建文件Observer.go
package observer
type Observer interface {
Update(subject *Subject)
}
创建文件Reader.go
package observer
import "fmt"
// 读取类
type Reader struct {
Name...
创建文件Manger.go
package chain
// 主管 经理 总经理 董事长
// 20 100 150 200
type Manger interface {
HaveRight(money int) bool // 判断权限
HandleFeeRequ...
创建文件ImageFlyWeight.go
package FlyWeight
import "fmt"
type ImageFlyWeight struct {
data string
}
// 初始化
func NewImageFlyWeight(filename string) *ImageFlyWeight {
data :=...
创建文件Component.go
package Deacorator
type Component interface {
Calc() int
}
type ConcreateComponent struct {
}
func (*ConcreateComponent) Calc() int {
return 0
}
创建...
创建文件Message.go
package bridge
// SNS短信
// Email
type AbstractMessage interface {
SendMessage(text, to string) // 发送快,普通发送
}
type MessageImlementer interface {
Send...
package main
import "fmt"
// 测试
type API interface {
Test() string
}
type APICall struct {
// 接口
a AmoudleAPI
b BmoudleAPI
}
func (api *APICall) Test() string...
package main
import "fmt"
type Subject interface {
Do() string // 实际业务, 业务系统,检查是否欠费,检查密码是否正确
}
type RealSubject struct {
}
func (sb RealSubject) Do() stri...
创建文件:Component.go
package Composite
//有的时候是父节点,叶子
type Component interface {
Parent() Component
SetParent(Component)
Name() string
SetName(string)
AddC...
package main
import "fmt"
// 适配器目标接口
type Target interface {
Request(int, int) string
}
type Adapter struct {
Adaptee
}
func NewAdapter(adaptee Adaptee) Target {
...