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 {
Pet
*Pet
currentChaseTarget *Pet
}
func NewDog(name string) *Dog {
dog := &Dog{}
dog.Name = name
return dog
return &Dog{Pet: NewPet(name)}
}
func (d *Dog) Chase(target *Pet) string {
@ -47,6 +45,12 @@ func main() {
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.Chase(cat))