This repository has been archived on 2021-09-07. You can view files and clone it, but cannot push or open issues or pull requests.

48 lines
750 B
Go
Raw Normal View History

2018-01-06 23:46:59 +04:00
package prototye
import "fmt"
import "errors"
const (
WHITE = 1
GREEN = 2
BLACK = 3
)
type ProductInfoGetter interface {
GetInfo() string
}
type Tshirt struct {
Size string
Color string
}
func (t Tshirt) GetInfo() string {
return fmt.Sprintf("Tshirt size: '%s', Color: '%s'.", t.Size, t.Color)
}
var whiteTshirt *Tshirt = &Tshirt{ "M", "white" }
var greenTshirt *Tshirt = &Tshirt{ "L", "green" }
var blackTshirt *Tshirt = &Tshirt{ "S", "black" }
func GetTshirClone(t int) (ProductInfoGetter, error) {
switch t {
case WHITE:
return whiteTshirt, nil
case GREEN:
return greenTshirt, nil
case BLACK:
return blackTshirt, nil
default:
return nil, errors.New(fmt.Sprintf("Prototype id %d not recognized.", t))
}
}