mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 04:36:02 +03:00
Create new factory function
* CreateVehicleFactory function initiate a new factory of Car or Motorbike
This commit is contained in:
parent
ffebe52a4f
commit
c3ace1a31b
14
creational/abstract_factory.md
Normal file
14
creational/abstract_factory.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Abstract Factory Pattern
|
||||
|
||||
## Implementation
|
||||
|
||||
```go
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
```go
|
||||
```
|
||||
|
||||
## Rules of Thumb
|
22
creational/abstract_factory/abstract_factory.go
Normal file
22
creational/abstract_factory/abstract_factory.go
Normal 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))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user