Skip to content

Instantly share code, notes, and snippets.

@cyantarek
Last active June 18, 2018 10:29
Show Gist options
  • Save cyantarek/c12c88ce6a006da40a383c19f3cdcd8c to your computer and use it in GitHub Desktop.
Save cyantarek/c12c88ce6a006da40a383c19f3cdcd8c to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type Square struct {
side float64
}
func (s Square) area() float64 {
return s.side * s.side
}
type Circle struct {
radius float64
}
func (c Circle) area() float64 {
return 2 * 3.1416 * c.radius * c.radius
}
type Shape interface {
area() float64
}
func info(s Shape) {
fmt.Println(s)
fmt.Println(s.area())
}
func main() {
s := Square{10}
c := Circle{10}
info(s)
info(c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment