Skip to content

Instantly share code, notes, and snippets.

@achilles42
Created October 11, 2015 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achilles42/13b1daa5434af00f7806 to your computer and use it in GitHub Desktop.
Save achilles42/13b1daa5434af00f7806 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Shaper interface {
Area() int
}
type Rectangle struct {
length, width int
}
func (r *Rectangle) Area() int {
return r.length * r.width
}
type Square struct {
length int
}
func (s *Square) Area() int {
return s.length * s.length
}
func main() {
//r := &Square{3}
r := &Rectangle{4, 6}
fmt.Println(r)
s := Shaper(r)
fmt.Println("Area : ", s.Area())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment