Skip to content

Instantly share code, notes, and snippets.

@bolilla
Created April 26, 2015 20:54
Show Gist options
  • Save bolilla/4db7daa7ec451f29ae25 to your computer and use it in GitHub Desktop.
Save bolilla/4db7daa7ec451f29ae25 to your computer and use it in GitHub Desktop.
GoPadawan InterfacesWithInterfaces
package main
import "fmt"
type hablador interface {
hablar()
}
type perro string
func (p perro) hablar() {
fmt.Println("Guau, guau! Soy un perro llamado", p)
}
type gato string
func (g gato) hablar() {
fmt.Println("Miau, miau! Soy un gato llamado:", g)
}
func miMascotaHablando(h hablador) {
fmt.Print("A ver mi peluchito cómo habla... ")
h.hablar()
}
func main() {
var miPerro perro = "Lassie"
var miGato gato = "Mizifú"
miMascotaHablando(miPerro)
miMascotaHablando(miGato)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment