直接上代碼:
package main import "fmt" //現(xiàn)在有個屌絲,有個擼管方法,我們的需求是在擼管前后***子穿褲子 type diaosi struct { } func (b *diaosi) LUALU() { fmt.Println("EN... 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() { //吊絲擼啊擼 b := &diaosi{} b.LUALU() fmt.Println("===========") //吊絲 ***子->擼啊擼->穿褲子 c := decorat(b) c.LUALU() //作業(yè):屌絲打開×××->***子->擼啊擼->穿褲子->關(guān)××× 怎么實現(xiàn)? }