PHP7 FactoryMethod

This commit is contained in:
Dominik Liebler
2016-09-22 13:28:46 +02:00
parent 6a98bcb73b
commit 4760d898a0
11 changed files with 94 additions and 159 deletions

View File

@@ -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");
}