mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 14:26:04 +03:00
ffebe52a4f
* To implements VehicleFactory the name of the function is changed
25 lines
427 B
Go
25 lines
427 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
SportMotorbikeType = 1
|
|
CruiseMotorbikeType = 2
|
|
)
|
|
|
|
type MotorbikeFactory struct{}
|
|
|
|
func (m *MotorbikeFactory) NewVehicle(v int) (Vehicle, error) {
|
|
switch v {
|
|
case SportMotorbikeType:
|
|
return new(SportMotorbike), nil
|
|
case CruiseMotorbikeType:
|
|
return new(CruiseMotorbike), nil
|
|
default:
|
|
return nil, errors.New(fmt.Sprintf("Motor bike of type %d not exist\n", v))
|
|
}
|
|
}
|