TransportFactory
надо объединить с Transport
interface TransportInterface
{
public function getItems();
}
class Car implements TransportInterface
{
public function getItems()
{
return ['Lada', 'KIA'];
}
}
class Bus implements TransportInterface
{
public function getItems()
{
return ['MAN'];
}
}
class Plane implements TransportInterface
{
public function getItems()
{
return ['Phoenix', 'Herpa'];
}
}
abstract class TransportFactory
{
abstract protected function createTransport(string $type): TransportInterface;
public function create(string $type): TransportInterface
{
$obj = $this->createTransport($type);
return $obj;
}
}
class Transport extends TransportFactory
{
protected function createTransport(string $type): TransportInterface
{
return new $type();
}
}
$carItems = (new Transport)->create('Car')->getItems();
Exploding, чтобы дерево построить