コード例 #1
0
    }
}
class BMW extends Car
{
    public function getMaxSpeed()
    {
        return 260;
    }
    public function getWeight()
    {
        return 2500;
    }
}
class Lada extends Car
{
    public function getMaxSpeed()
    {
        return 100;
    }
    public function getWeight()
    {
        return 3000;
    }
}
$carsFactory = new CarsFactory();
$cars['toyota'] = $carsFactory->createCar('toyota');
$cars['bmw'] = $carsFactory->createCar('bmw');
foreach ($cars as $mod => $obj) {
    echo 'Max speed: ' . $mod . " = " . $obj->getMaxSpeed();
    echo ' Weight: ' . $mod . " = " . $obj->getWeight() . '<br>';
}