mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-21 20:36:01 +03:00
Added oct cat example
This commit is contained in:
parent
ab40a74092
commit
57942eb8a0
29
openclose/main.go
Normal file
29
openclose/main.go
Normal file
@ -0,0 +1,29 @@
|
||||
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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user