go语言中interface的实践
package main import ( "fmt" "math" ) type geometry interface { area() float64 perim() float64 } type square struct { width, height float64 } type circle struct { radius float64 } //要在go中实现一个接口,我们只需要实现接口中的所有方法 //`square`的实现,s接收者接受了area()方法 func (s square) area() float64 { return s.width * s.height } //`square`的实现,s接收者接受了perim()方法 func (s square) per...阅读全文