Go Decoration Mode, the Story of a loser
Go directly to the code:
Package mainimport "fmt" / / now there is a loser, there is a management method, our requirement is to wear pants type diaosi struct {} func (b * diaosi) LUALU () {fmt.Println ("EN...") before and after the pipe. a.。 A...OH GOD..FUCK.. me.. ")} type decorator struct {* diaosi LUALU func ()} func decorat (b * diaosi) (d * decorator) {d = & decorator {b, nil} d.LUALU = func () {fmt.Println (" take off trousers... ") B.LUALU () fmt.Println ("take on trousers...")} return} func main () {/ / hanging wire LOL b: = & diaosi {} b.LUALU () fmt.Println ("=") / / hanging wire * sub-> LOL-> wearing trousers c: = decorat (b) c.LUALU () / / Job: losers open × × -> * * sub-> LOL-> wear pants-> Guan × × how to achieve it? }