Исходники и презентации
This commit is contained in:
34
lessons/interfaces/duck_typing/main.go
Normal file
34
lessons/interfaces/duck_typing/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Need to show solution
|
||||
|
||||
type Duck interface {
|
||||
Talk() string
|
||||
Walk()
|
||||
Swim()
|
||||
}
|
||||
|
||||
type Dog struct{}
|
||||
|
||||
func (d Dog) Talk() string {
|
||||
return "AAAGGGRRR"
|
||||
}
|
||||
|
||||
func (d Dog) Walk() {
|
||||
fmt.Println("Walking...")
|
||||
}
|
||||
|
||||
func (d Dog) Swim() {
|
||||
fmt.Println("Swimming...")
|
||||
}
|
||||
|
||||
func CatchDuck(duck Duck) {
|
||||
fmt.Println("Catching...")
|
||||
}
|
||||
|
||||
func main() {
|
||||
dog := Dog{}
|
||||
CatchDuck(dog)
|
||||
}
|
||||
Reference in New Issue
Block a user