type write interface {
puts()
}
type member struct {
name string
age int
}
func NewMember(name string, age int) *member {
return &member{
name: name,
age: age,
}
}
func (m *member) puts() {
fmt.Println(m.name)
}
func (m *member) readSth() {
fmt.Println(m.age)
}
func testPutsAndRead(write write) {
if m, ok := write.(interface{ readSth() }); ok {
m.readSth()
}
write.puts()
}
var _ write = (*member)(nil)
func main() {
m := NewMember("test Name", 19)
testPutsAndRead(m)
}