Last active
February 28, 2020 22:45
-
-
Save bneil/568b0f85d43e407e94de891ef57876af to your computer and use it in GitHub Desktop.
Golang Example Type/Interface Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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