design-patterns/code/prototype.php
2025-07-04 13:35:51 +03:00

41 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-04
* @time: 08:13
*/
declare(strict_types = 1);
use Pattern\Creational\Prototype\Author;
use Pattern\Creational\Prototype\Page;
function client(): void
{
$author = new Author("Джордж Орвелл");
$page = new Page(
"Колгосп тварин",
"Притча, сповнена гіркої іронії і сарказму.
Трагікомічна історія спільноти тварин, що зважилися позбутися пригноблення людьми,
і потрапила під бузувірську владу свиней.",
$author
);
// ...
$page->addComment("Nice book!");
// ...
$draft = clone $page;
echo "Dump of the clone. Note that the author is now referencing two objects.\n\n";
/** @noinspection ForgottenDebugOutputInspection */
dump($draft);
}
?><img class="diagram" src="/assets/img/diagrams/prototype.png" alt="Adapter DEsign Pattern Diagram"><?php
client();