Created
April 26, 2015 20:54
-
-
Save bolilla/4db7daa7ec451f29ae25 to your computer and use it in GitHub Desktop.
GoPadawan InterfacesWithInterfaces
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 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