awesome-patterns/creational/abstract_factory/abstract_factory.go
Lucas Alves c3ace1a31b Create new factory function
* CreateVehicleFactory function initiate a new factory of
	  Car or Motorbike
2021-07-01 00:59:42 -03:00

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))
}
}