Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bolilla/3fed4b0fe5ab038c8ddc to your computer and use it in GitHub Desktop.
Save bolilla/3fed4b0fe5ab038c8ddc to your computer and use it in GitHub Desktop.
GoPadawan CompoInterfaces Composicion
package main
import "fmt"
type motor struct {
ruido string
}
func (n motor) hacerRuido() string {
return fmt.Sprintf("Este motor hace: %s", n.ruido)
}
type cosaRuidosa interface {
hacerRuido() string
}
type naveEspacial struct {
numLasers int
capcidadPasajeros int
motor
}
func main() {
var miMotor = motor{"¡Brrroum!"}
var miNave = naveEspacial{4, 2, miMotor}
fmt.Println(miNave.hacerRuido())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment