Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AnggotaKeluarga
- {
- private $name;
- public function __construct($name)
- {
- $this->name = $name;
- }
- public function getName()
- {
- return $this->name;
- }
- }
- class Keluarga
- {
- private $father;
- private $mother;
- private $children;
- public function __construct($father, $mother)
- {
- $this->father = $father;
- $this->mother = $mother;
- $this->children = [];
- }
- public function addChildren($child)
- {
- $this->children[] = $child;
- }
- public function getFatherName()
- {
- return $this->father->getName();
- }
- public function getMotherName()
- {
- return $this->mother->getName();
- }
- public function getChildren()
- {
- return $this->children;
- }
- }
- $salsa = new AnggotaKeluarga('Salsabila');
- $ayahSalsa = new AnggotaKeluarga('Ayah Salsa');
- $ibuSalsa = new AnggotaKeluarga('Ibu Salsa');
- $keluargaSalsa = new Keluarga($ayahSalsa, $ibuSalsa);
- $keluargaSalsa->addChildren($salsa);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Test</title>
- </head>
- <body>
- <svg height="150" width="170">
- <text x="0" y="20" fill="red"><?= $keluargaSalsa->getFatherName() ?></text>
- <text x="90" y="20" fill="red"><?= $keluargaSalsa->getMotherName() ?></text>
- <line x1="25" y1="25" x2="25" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
- <line x1="125" y1="25" x2="125" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
- <line x1="23" y1="75" x2="127" y2="75" style="stroke:rgb(255,0,0);stroke-width:3" />
- <line x1="75" y1="75" x2="75" y2="125" style="stroke:rgb(255,0,0);stroke-width:3" />
- <text x="32.5" y="150" fill="red"><?= $keluargaSalsa->getChildren()[0]->getName() ?></text>
- </svg> <br>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement