Last active
August 1, 2022 13:22
-
-
Save arashicage/51d056fbb06a39142e7938755e9a0672 to your computer and use it in GitHub Desktop.
23 design patterns
This file contains hidden or 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
| 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支付成功" | |
| } |
This file contains hidden or 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
| 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