cs FactoryMethod

This commit is contained in:
Dominik Liebler
2013-09-11 16:35:18 +02:00
parent 754ea98fb2
commit b05f57064f
7 changed files with 51 additions and 61 deletions

View File

@@ -1,39 +1,31 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\FactoryMethod;
/**
* GermanFactory is vehicle factory in Germany
* GermanFactory is a vehicle factory in Germany
*/
class GermanFactory extends FactoryMethod
{
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function createVehicle($type)
{
switch ($type) {
case parent::CHEAP :
case parent::CHEAP:
return new Bicycle();
break;
case parent::FAST :
case parent::FAST:
$obj = new Porsche();
// we can specialize the way we want some concrete Vehicle since
// we know the class
$obj->addTuningAMG();
return $obj;
break;
default :
throw new \InvalidArgumentException("$type is not a valid vehicle");
}
}
}
}