golang 设计模式之装饰器模式


package main
import "fmt"
type active struct {
       id int
}

func (a *active) active() {
       fmt.Printf("%d 激活啦\n",a.id)
}

func (a *active) unactive() {
       fmt.Printf("%d 取消激活啦\n",a.id)
}

type activeLog struct {
       activeT active
}

func (a *activeLog) active()  {
    fmt.Println("active before")
    a.activeT.active()
    fmt.Println("active after")
}

func main(){
   ac:=&active{id:1}
   acl:=&activeLog{activeT:*ac}
   acl.active()
}