mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-12-01 17:36:09 +03:00
25 lines
378 B
Go
25 lines
378 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
LuxuryCarType = 1
|
|
FamilyCarType = 2
|
|
)
|
|
|
|
type CarFactory struct{}
|
|
|
|
func (c *CarFactory) NewVehicle(v int) (Vehicle, error) {
|
|
switch v {
|
|
case LuxuryCarType:
|
|
return new(LuxuryCar), nil
|
|
case FamilyCarType:
|
|
return new(FamilyCar), nil
|
|
default:
|
|
return nil, errors.New(fmt.Sprintf("Vehicle of type %d not exist\n", v))
|
|
}
|
|
}
|