organize structural patterns

This commit is contained in:
Edward 2020-05-08 17:07:20 +08:00
parent 560478d5cf
commit b3ac04909d
4 changed files with 9 additions and 8 deletions

View File

@ -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

View File

@ -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