go裝飾模式,一個屌絲擼管的故事

直接上代碼:

package main

import "fmt"

//現在有個屌絲,有個擼管方法,我們的需求是在擼管前後***子穿褲子
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()
    //作業:屌絲打開毛片->***子->擼啊擼->穿褲子->關毛片 怎麼實現?
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章