Skip to content

Instantly share code, notes, and snippets.

@maxwellgithinji
Created July 27, 2020 09:11
Show Gist options
  • Save maxwellgithinji/e2230e39d476714f6e611f471842fef0 to your computer and use it in GitHub Desktop.
Save maxwellgithinji/e2230e39d476714f6e611f471842fef0 to your computer and use it in GitHub Desktop.
// A type may have a method set associated with it. The method set of an interface type is its interface.
// type T
// The method set of any other type T consists of all methods declared with receiver type T.
package main
import (
"fmt"
)
type Person struct {
first string
}
type secretAgent struct {
Person
ltk bool
}
func (p Person) speak() {
fmt.Println("from person", p.first)
}
func (sa secretAgent) speak() {
fmt.Println("from secret agent", sa.first)
}
type human interface {
speak()
}
func saySomething(h human) {
h.speak()
}
func main() {
p1 := Person{
first: "Jorgen",
}
sa1 := secretAgent{
Person: Person{
first: "Ula Britta Frita Smirta",
},
ltk: true,
}
saySomething(p1)
saySomething(sa1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment