overriding a child method
tags: learning go programming
content
- in this example:
go-embedded-struct-method-promotion#method-promotion
- parent
Playerhas its inner struct’s methodMove Playercan also overrides it with its ownMove:
func (p Player) Move() {}- it can even uses the inner struct’s method
Movein its ownMove:
func (p Player) Move(dx, dy int) {
position := p.Position.Move(dx, dy)
p.X = position.X
p.Y = position.Y
}