Goofing around with pseudo-inheritance variations
This commit is contained in:
parent
31975286f5
commit
fc144fc403
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user