4 ms·
You can use object composition: http://play.golang.org/p/jyS38luYjM http://play.golang.org/p/jyS38luYjM Then make a Draw() method on the single object default
by doragcoder 11y ago
You can use object composition: http://play.golang.org/p/jyS38luYjM http://play.golang.org/p/jyS38luYjM
Then make a Draw() method on the single object default to what you expect. The simple inline explanation is:
type SingleObject struct {
Cowboy
Shape
}
Access is as follows to be unambiguous:
Woody.Cowboy.Draw()
Woody.Shape.Draw()
- TheDong 11y agoThe problem is that you can't differentiate SingleObject from CowboyObject and ShapeObject. They all are the same interface and can be passed into each other's methods, leading to a logical error.