mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2025-04-10 12:31:02 +00:00
22 lines
324 B
Go
22 lines
324 B
Go
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))
|
|
}
|
|
}
|