什么是简单工厂模式
简单工厂模式又被称为静态工厂方法模式(Static Factory Method)
具体就是通过这个工厂类的方法来创建对象
```
<?php
abstract class Product
{
abstract function play();
}
class A extends Product
{
public function play()
{
echo 'I play CS:GO';
}
}
class B extends Product
{
public function play()
{
echo 'I am playing LOL';
}
}
class SimpleFactory
{
static function create($name)
{
switch($name) {
case 'cs':
return new A();
break;
case 'lol':
return new B();
break;
default:
break;
}
}
}
$obj_1 = SimpleFactory::create('cs');
$obj_1->play(); // I play CS:GO
$obj_2 = SimpleFactory::create('lol');
$obj_2->play(); // I am playing LOL