mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-16 12:56:21 +02:00
19 lines
470 B
PHP
19 lines
470 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Creational\FactoryMethod;
|
|
|
|
class ItalianFactory extends FactoryMethod
|
|
{
|
|
protected function createVehicle(string $type): VehicleInterface
|
|
{
|
|
switch ($type) {
|
|
case parent::CHEAP:
|
|
return new Bicycle();
|
|
case parent::FAST:
|
|
return new CarFerrari();
|
|
default:
|
|
throw new \InvalidArgumentException("$type is not a valid vehicle");
|
|
}
|
|
}
|
|
}
|