-
-
Save nnao45/4017af619553cee31734cf89caa0f0c1 to your computer and use it in GitHub Desktop.
golang interface
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 Animal struct { | |
Cat string | |
Dog string | |
} | |
func newAnimal() *Animal { | |
return &Animal { | |
Cat: "cat", | |
Dog: "dog", | |
} | |
} | |
type Count interface { | |
One() string | |
Two() string | |
} | |
func(a Animal) One() string{ | |
return "one" | |
} | |
func(a Animal) Two() string{ | |
return "two" | |
} | |
func main() { | |
a := newAnimal() | |
c := Count(a) | |
fmt.Println(a.Cat) | |
fmt.Println(a.Dog) | |
fmt.Println(c.One()) | |
fmt.Println(c.Tow()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment