awesome-patterns/creational/abstract_factory/abstract_factory.go

23 lines
324 B
Go
Raw Normal View History

package main
import (
"errors"
"fmt"
)
const (
CAR = 1
BIKE = 2
)
func CreateVehicleFactory(v int) (VehicleFactory, error) {
switch v {
case CAR:
return new(CarFactory), nil
case BIKE:
return new(MotorbikeFactory), nil
default:
return nil, errors.New(fmt.Sprintf("Factory of type %d not exist\n", v))
}
}