baggiiiie

~

/

zettelkasten

/

go embedded struct method override

go-embedded-struct-method-override

Feb 01, 2026

  • learning
  • go
  • programming

overriding a child method

tags: learning go programming

content

  • in this example:
    go-embedded-struct-method-promotion#method-promotion
  • parent Player has its inner struct’s method Move
  • Player can also overrides it with its own Move:
func (p Player) Move() {}
  • it can even uses the inner struct’s method Move in its own Move:
func (p Player) Move(dx, dy int) {
	position := p.Position.Move(dx, dy)
	p.X = position.X
	p.Y = position.Y
}

up

  • go-embedded-struct-method-promotion

down

reference


Graph View

  • overriding a child method
  • content
  • up
  • down
  • reference

baggiiiie's learning notes on tech stuff