mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 04:36:02 +03:00
c3ace1a31b
* CreateVehicleFactory function initiate a new factory of Car or Motorbike
23 lines
324 B
Go
23 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))
|
|
}
|
|
}
|