Last active
June 18, 2018 10:29
-
-
Save cyantarek/c12c88ce6a006da40a383c19f3cdcd8c to your computer and use it in GitHub Desktop.
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
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