mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-24 21:46:03 +03:00
44 lines
580 B
Go
44 lines
580 B
Go
|
package shape
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"github.com/davecgh/go-spew/spew"
|
||
|
)
|
||
|
|
||
|
type Shape interface {
|
||
|
Draw()
|
||
|
}
|
||
|
|
||
|
type Circle struct {
|
||
|
}
|
||
|
|
||
|
func (c *Circle) Draw() {
|
||
|
spew.Dump("Draw Circle")
|
||
|
}
|
||
|
|
||
|
type Square struct {
|
||
|
}
|
||
|
|
||
|
func (s *Square) Draw() {
|
||
|
spew.Dump("Draw Square")
|
||
|
}
|
||
|
|
||
|
type Rec struct {
|
||
|
}
|
||
|
|
||
|
func (r *Rec) Draw() {
|
||
|
spew.Dump("Draw Rec")
|
||
|
}
|
||
|
|
||
|
func GetShape(shape string) (Shape, error) {
|
||
|
if shape == "Circle" {
|
||
|
return &Circle{}, nil
|
||
|
} else if shape == "Square" {
|
||
|
return &Square{}, nil
|
||
|
} else if shape == "Rec" {
|
||
|
return &Rec{}, nil
|
||
|
}
|
||
|
return nil, errors.New("Shape not found")
|
||
|
}
|