Create new factory function

* CreateVehicleFactory function initiate a new factory of
	  Car or Motorbike
This commit is contained in:
Lucas Alves 2021-07-01 00:59:42 -03:00
parent ffebe52a4f
commit c3ace1a31b
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# Abstract Factory Pattern
## Implementation
```go
```
## Usage
```go
```
## Rules of Thumb

View File

@ -0,0 +1,22 @@
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))
}
}