Skip to content

Instantly share code, notes, and snippets.

@josephspurrier
Created May 19, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephspurrier/25d2ee03833a1e6eab33cc9b49956515 to your computer and use it in GitHub Desktop.
Save josephspurrier/25d2ee03833a1e6eab33cc9b49956515 to your computer and use it in GitHub Desktop.
Method Overriding in Go
package main
import "fmt"
type foo struct{}
func (f foo) Start() {
fmt.Println("Foo Started")
}
func (f foo) Call() {
fmt.Println("Foo Called")
}
func (f baz) Call() {
fmt.Println("Baz Called")
}
type baz struct {
foo
}
func main() {
foo{}.Call() // This output: Foo Called
foo{}.Start() // This output: Foo Started
baz{}.Call() // This outputs: Baz Called
baz{}.Start() // This outputs: Foo Started
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment