Last active
September 21, 2021 23:59
-
-
Save aryadiahmad4689/a72fae954632f09c6f0acffb06245791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface Prototype { | |
public function clone(): Prototype; | |
} | |
class Pesawat implements Prototype{ | |
private $mesin; | |
private $kursi; | |
public function setMesin(string $mesin) | |
{ | |
$this->mesin = $mesin; | |
} | |
public function setKursi(int $kursi) | |
{ | |
$this->kursi =$kursi; | |
} | |
public function buatPesawat() | |
{ | |
echo $this->mesin." ".$this->kursi; | |
} | |
public function clone(): Pesawat | |
{ | |
$pesawat = new Pesawat; | |
$pesawat->mesin = $this->mesin; | |
$pesawat->kursi = $this->kursi; | |
return $pesawat; | |
} | |
} | |
$pesawat1 = new Pesawat; | |
$pesawat1->setMesin("Kargo"); | |
$pesawat1->setKursi(40); | |
print_r($pesawat1->buatPesawat()); | |
// output = Kargo 40 | |
$pesawat2 = $pesawat1->clone(); | |
$pesawat2->setKursi(200); | |
print_r($pesawat2->buatPesawat()); | |
// output = Kargo 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment