Skip to content

Instantly share code, notes, and snippets.

@johnvilsack
Created June 23, 2014 18:08
Show Gist options
  • Save johnvilsack/ca090f90e8852477d080 to your computer and use it in GitHub Desktop.
Save johnvilsack/ca090f90e8852477d080 to your computer and use it in GitHub Desktop.
How Interfaces Work
package main
import (
"fmt"
)
type ZipCoder interface {
fullName() string
}
type CustRecord struct {
FirstName, LastName string
}
func (c CustRecord) fullName() string {
return c.FirstName + " :: " + c.LastName
}
func main() {
CustOne := CustRecord{"John", "Vilsack"}
CustTwo := CustRecord{"Rachel", "Vilsack"}
fmt.Printf("%v", ZipCoder.fullName(CustOne))
fmt.Printf("%v", ZipCoder.fullName(CustTwo))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment