Skip to content

Instantly share code, notes, and snippets.

@arashicage
Last active August 1, 2022 13:22
Show Gist options
  • Select an option

  • Save arashicage/51d056fbb06a39142e7938755e9a0672 to your computer and use it in GitHub Desktop.

Select an option

Save arashicage/51d056fbb06a39142e7938755e9a0672 to your computer and use it in GitHub Desktop.
23 design patterns
package factorymethod
import "fmt"
type Pay interface {
Pay(string) int
}
type PayReq struct {
OrderId string
}
type APayReq struct {
PayReq
}
func (p *APayReq) Pay() string {
// todo
fmt.Println(p.OrderId)
return "APay支付成功"
}
type BPayReq struct {
PayReq
Uid int64
}
func (p *BPayReq) Pay() string {
// todo
fmt.Println(p.OrderId)
fmt.Println(p.Uid)
return "BPay支付成功"
}
package main
type Command interface {
execute()
// execute() error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment