mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-03 21:47:25 +02:00
the REAL factory method pattern
This commit is contained in:
32
FactoryMethod/GermanFactory.php
Normal file
32
FactoryMethod/GermanFactory.php
Normal 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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user