|
|
|
|
|
by rakoo
3437 days ago
|
|
> With proper composition, your child objects are named, and you can choose which interfaces you want to delegate to which object. This doesn't just give you better control over which functionality you wish to expose, but also avoids conflict when two member objects implement the same interface. Oh but you can avoid that, it's part of the language, see this link: https://golang.org/doc/effective_go.html#embedding Typically, you can have something like this: type lockedReader struct {
io.Reader
sync.Mutex
}
lr := lockerReader{someReader, sync.Mutex{}}
lr.Lock()
lr.Read(...)
lr.Unlock()
By default, methods will be delegated to the first field that has the method. If you want something else, you are free to override this default behavior. |
|
This is how a diamond looks like: