-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04bfefe
commit 095d611
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type People interface { | ||
GetName() string | ||
GetAge() int | ||
|
||
GetData() people | ||
} | ||
|
||
type people struct { | ||
name string | ||
} | ||
|
||
func (p people) GetName() string { | ||
return p.name | ||
} | ||
|
||
func (p people) GetData() people { | ||
return p | ||
} | ||
|
||
func NewPeople(name string) people { | ||
return people{ | ||
name: name, | ||
} | ||
} | ||
|
||
type Ming struct { | ||
people | ||
age int | ||
} | ||
|
||
func (x Ming) GetAge() int { | ||
return x.age | ||
} | ||
|
||
//func (x Ming) GetName() string { | ||
// return "daming" | ||
//} | ||
|
||
func NewMing() People { | ||
return Ming{ | ||
people: NewPeople("xiaoming"), | ||
age: 18, | ||
} | ||
} | ||
|
||
func main() { | ||
m := NewMing() | ||
|
||
fmt.Println(m.GetAge()) | ||
fmt.Println(m.GetName()) | ||
fmt.Println(m.GetData()) | ||
} |