Fabryka abstrakcyjna

<?php

interface CarType {

    CONST POTROL = 'petrol';
    CONST DIESEL = 'desiel';

}

class CarsFactory {

    public function createDesiel() {
        return new Car(CarType::DIESEL, '1.7', false);
    }

    public function createFastBigCar() {
        return new Car(CarType::POTROL, '3.7', false);
    }

    public function createFastSmallCar() {
        return new Car(CarType::POTROL, '1.0', true);
    }

}

Class Car {

    private $engine;
    private $capacity;
    private $turbo;

    public function __construct(string $engine, string $capacity, bool $turbo) {
        $this->engine = $engine;
        $this->capacity = $capacity;
        $this->turbo = $turbo;
    }

}

$factory = new CarsFactory();

$diesel = $factory->createDesiel();
$fastBigCar = $factory->createFastBigCar();
$fastSmallCar = $factory->createFastSmallCar();

var_dump($diesel, $fastBigCar, $fastSmallCar);
Komentarze wyłączone