Addded Prototype Desin Pattern

This commit is contained in:
2025-07-04 09:05:39 +03:00
parent 979ae42cde
commit 1cf6e3d7d2
5 changed files with 310 additions and 3 deletions

40
code/prototype.php Normal file
View File

@@ -0,0 +1,40 @@
<?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);
}
client();