Goofing around with pseudo-inheritance variations

This commit is contained in:
Dan Buch 2015-07-25 14:28:28 -04:00
parent 31975286f5
commit fc144fc403

View File

@ -17,15 +17,13 @@ func (p *Pet) Run() string {
} }
type Dog struct { type Dog struct {
Pet *Pet
currentChaseTarget *Pet currentChaseTarget *Pet
} }
func NewDog(name string) *Dog { func NewDog(name string) *Dog {
dog := &Dog{} return &Dog{Pet: NewPet(name)}
dog.Name = name
return dog
} }
func (d *Dog) Chase(target *Pet) string { func (d *Dog) Chase(target *Pet) string {
@ -47,6 +45,12 @@ func main() {
dog := NewDog("Fido") dog := NewDog("Fido")
fmt.Printf("%#v\n", dog)
dog.Run()
fmt.Printf("%#v\n", dog)
fmt.Printf("%#v\n", dog) fmt.Printf("%#v\n", dog)
fmt.Printf("%#v\n", dog.Chase(cat)) fmt.Printf("%#v\n", dog.Chase(cat))