awesome-patterns/openclose/main.go

30 lines
316 B
Go
Raw Normal View History

2018-03-10 16:34:31 +03:00
package main
import "fmt"
type Cat struct {
Name string
}
func (c Cat) Legs() int {
return 4
}
func (c Cat) PrintLegs() {
fmt.Printf("I have %d legs", c.Legs())
}
type OctCat struct {
Cat
}
func (o OctCat) Legs() int {
return 5
}
func main() {
var oct OctCat
fmt.Println(oct.Legs())
oct.PrintLegs()
}