diff --git a/structural/proxy.md b/structural/proxy.md index 19d66f7..82f676c 100644 --- a/structural/proxy.md +++ b/structural/proxy.md @@ -8,37 +8,37 @@ The proxy could interface to anything: a network connection, a large object in m Short idea of implementation: ```go + // To use proxy and to object they must implement same methods type IObject interface { ObjDo(action string) } + // Object represents real objects which proxy will delegate data type Object struct { action string } + // ObjDo implements IObject interface and handels all logic func (obj *Object) ObjDo(action string) { - // Action handler + // Action behaiver fmt.Printf("I can, %s", action) } + // ProxyObject represents proxy object with intercepts actions type ProxyObject struct { object *Object } + // ObjDo are implemented IObject and intercept action before send in real Object func (p *ProxyObject) ObjDo(action string) { if p.object == nil { p.object = new(Object) } if action == "Run" { - p.object.ObjDo(action) + p.object.ObjDo(action) // Prints: I can, Run } } - - func main() { - newObj := new(ProxyObject) - newObj.ObjDo("Run") // Prints: I can, Run - } ``` ## Usage -For usage, see [proxy/main.go](proxy/main.go) or [view in the Playground](). +For more complex usage, see [proxy/main.go](proxy/main.go) or [view in the Playground](https://play.golang.org/p/VswGMpz-gp).