the REAL factory method pattern

This commit is contained in:
Trismegiste
2013-05-10 21:09:55 +02:00
parent 9b7330795d
commit cc765bde41
8 changed files with 235 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\FactoryMethod;
/**
* GermanFactory is vehicle factory in Germany
*/
class GermanFactory extends FactoryMethod
{
/**
* @inheritdoc
*/
protected function createVehicle($type)
{
switch ($type) {
case 'cheap' :
return new Bicycle();
break;
case 'fast' :
return new Porsche();
break;
default :
throw new \InvalidArgumentException("$type is not a valid vehicle");
}
}
}