Skip to content

Instantly share code, notes, and snippets.

@bneil
Last active February 28, 2020 22:45
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 bneil/568b0f85d43e407e94de891ef57876af to your computer and use it in GitHub Desktop.
Save bneil/568b0f85d43e407e94de891ef57876af to your computer and use it in GitHub Desktop.
Golang Example Type/Interface Inheritance
package main
import (
"fmt"
)
type Funny interface {
Joke()
}
type Comedian struct {
Name string
Age int
}
type RedSkelton Comedian
type WillardScott Comedian
func (e RedSkelton) Joke() {
fmt.Println(fmt.Sprintf("hi %s", e.Name))
}
func (e WillardScott) Joke() {
fmt.Println(fmt.Sprintf("hi %s", e.Name))
}
func ffs(e Funny) {
e.Joke()
}
func main() {
var red RedSkelton
red.Name = "Red Skelton"
red.Joke()
var will WillardScott
will.Name = "Will Scott"
will.Joke()
ffs(red)
ffs(will)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment