Паттерны / Порождающие паттерны
image

<?php

//Prototype
class Shape  {
    public $lineCount = 0;

    function __construct(int $lineCount) {
        $this->lineCount = $lineCount;
    }

    function clone(): Shape {
        return clone $this;
    }
}

//ConcretePrototype
class Square extends Shape {
    function __construct() {
        parent::__construct(4);
    }
}

//Client
class ShapeMaker {    
    private $shape;

    function __construct(Shape $shape) {
        $this->shape = $shape;
    }

    function makeShape() {
        return $this->shape->clone();
    }
}

$square = new Square();
$maker = new ShapeMaker($square);

$square1 = $maker->makeShape();
$square2 = $maker->makeShape();

echo $square1->lineCount"\n";
echo $square1 === $square2 ? "true" : "false";


Описывает виды создаваемых объектов с помощью прототипа и создает новые объекты путем его копирования.