Answer the question
In order to leave comments, you need to log in
What pattern is suitable for this?
Hello, I can not decide which pattern will be the most convenient for this.
How to bind multiple classes in one? We have several classes Car
, Bus
, Plane
. All of these classes have one method getItems()
(all from the same interface, code below). How to connect them in one class Transport
?
For access to be like this:
$carItems = (new Transport)->setTransport('Car')->getItems();
$busItems = (new Transport)->setTransport('Bus')->getItems();
// а также
$carItems = (new Car)->getItems();
$busItems = (new Bus)->getItems();
interface TransportInterface
{
public function getItems();
}
class Car implements TransportInterface
{
public function getItems()
{
return [];
}
}
class Bus implements TransportInterface
{
public function getItems()
{
return [];
}
}
class Plane implements TransportInterface
{
public function getItems()
{
return [];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question