diff --git a/README.md b/README.md index bf70658..aa222d7 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,10 @@ A curated collection of idiomatic design & application patterns for Go language. |:-------:|:----------- |:------:| | [Bridge](/structural/bridge/main.go) | Decouples an interface from its implementation so that the two can vary independently | ✔ | | [Composite](/structural/composite/main.go) | Encapsulates and provides access to a number of different objects | ✔ | -| [Decorator](/structural/decorator.md) | Adds behavior to an object, statically or dynamically | ✔ | +| [Decorator](/structural/decorator/decorator.md) | Adds behavior to an object, statically or dynamically | ✔ | | [Facade](/structural/facade/main.go) | Uses one type as an API to a number of others | ✔ | | [Flyweight](/structural/flyweight/main.go) | Reuses existing instances of objects with similar/identical state to minimize resource usage | ✔ | -| [Proxy](/structural/proxy.md) | Provides a surrogate for an object to control it's actions | ✔ | +| [Proxy](/structural/decorator/proxy.md) | Provides a surrogate for an object to control it's actions | ✔ | ## Behavioral Patterns diff --git a/structural/decorate.go b/structural/decorator/decorate.go similarity index 80% rename from structural/decorate.go rename to structural/decorator/decorate.go index 4dccbe6..1f9c294 100644 --- a/structural/decorate.go +++ b/structural/decorator/decorate.go @@ -1,5 +1,7 @@ package main +import "log" + type Object func(int) int func LogDecorate(fn Object) Object { @@ -10,19 +12,18 @@ func LogDecorate(fn Object) Object { log.Println("Execution is completed with the result", result) - return result + return result } } func Double(n int) int { - return n * 2 + return n * 2 } -func main(){ - f := LogDecorate(Double) - f(5) +func main() { + f := LogDecorate(Double) + f(5) } - // Starting execution with the integer 5 // Execution is completed with the result 10 diff --git a/structural/decorator.md b/structural/decorator/decorator.md similarity index 100% rename from structural/decorator.md rename to structural/decorator/decorator.md diff --git a/structural/proxy.md b/structural/proxy/proxy.md similarity index 100% rename from structural/proxy.md rename to structural/proxy/proxy.md