From 7680a25f35c55ddc2be376f281e28450a03fde17 Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Wed, 23 Dec 2015 15:46:27 +0200 Subject: [PATCH] Add decorator pattern --- decorator.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 decorator.go diff --git a/decorator.go b/decorator.go new file mode 100644 index 0000000..4c4e846 --- /dev/null +++ b/decorator.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "log" +) + +func LogDecorate(fn func(s string)) func(s string) { + return func(s string) { + log.Println("Starting the execution with the argument", s) + fn(s) + log.Println("Execution is completed.") + } +} + +func Function(s string) { + fmt.Println(s) +} + +func main() { + f := LogDecorate(Function) + + f("Hello Decorator") +}