Addded Prototype Desin Pattern
This commit is contained in:
40
code/prototype.php
Normal file
40
code/prototype.php
Normal 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();
|
||||
Reference in New Issue
Block a user