awesome-patterns/creational/abstract_factory/motorbike_factory.go

25 lines
427 B
Go
Raw Permalink Normal View History

2018-01-14 08:43:41 +03:00
package main
import (
"errors"
"fmt"
)
const (
SportMotorbikeType = 1
CruiseMotorbikeType = 2
)
type MotorbikeFactory struct{}
func (m *MotorbikeFactory) NewVehicle(v int) (Vehicle, error) {
2018-01-14 08:43:41 +03:00
switch v {
case SportMotorbikeType:
return new(SportMotorbike), nil
case CruiseMotorbikeType:
return new(CruiseMotorbike), nil
default:
return nil, errors.New(fmt.Sprintf("Motor bike of type %d not exist\n", v))
}
}