32 lines
472 B
Go
32 lines
472 B
Go
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type Person struct {
|
||
|
Name string
|
||
|
}
|
||
|
|
||
|
func NewPerson(name string) *Person {
|
||
|
return &Person{
|
||
|
Name: name,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *Person) Wave() string {
|
||
|
return p.Name + " is waving"
|
||
|
}
|
||
|
|
||
|
func (p *Person) WaveAt(other *Person) string {
|
||
|
return p.Name + " waves at " + other.Name
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
boo := NewPerson("Boo")
|
||
|
fmt.Printf("%#v\n", boo.Wave())
|
||
|
|
||
|
hay := NewPerson("Hay")
|
||
|
fmt.Printf("%#v\n", hay.Wave())
|
||
|
|
||
|
fmt.Printf("%#v\n", boo.WaveAt(hay))
|
||
|
}
|