mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-08 16:06:31 +02:00
PHP7 FactoryMethod
This commit is contained in:
@@ -2,23 +2,15 @@
|
||||
|
||||
namespace DesignPatterns\Creational\FactoryMethod;
|
||||
|
||||
/**
|
||||
* ItalianFactory is vehicle factory in Italy.
|
||||
*/
|
||||
class ItalianFactory extends FactoryMethod
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createVehicle($type)
|
||||
protected function createVehicle(string $type): VehicleInterface
|
||||
{
|
||||
switch ($type) {
|
||||
case parent::CHEAP:
|
||||
return new Bicycle();
|
||||
break;
|
||||
case parent::FAST:
|
||||
return new Ferrari();
|
||||
break;
|
||||
return new CarFerrari();
|
||||
default:
|
||||
throw new \InvalidArgumentException("$type is not a valid vehicle");
|
||||
}
|
||||
|
Reference in New Issue
Block a user