Decorator Pattern
※ 定義 : 可以動態地為物件附加額外的職責。使用裝飾器來擴展功能比使用繼承更有彈性。
FunctionType 定義一個函數類型
1 | type FunctionType func(string) string |
Message 函數返回一個基本的消息
1 | func Message(name string) string { |
Decorator 函數,接受 FunctionType 類型參數,並返回新的 FunctionType
1 | func Decorator(fn FunctionType) FunctionType { |
執行
1 | func main() { |