Skip to content

Commit

Permalink
Create people.go (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyingjunz authored Jun 3, 2024
1 parent 04bfefe commit 095d611
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions practise/interface-practise/people.go
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())
}

0 comments on commit 095d611

Please sign in to comment.