Created
September 11, 2021 11:53
-
-
Save aryadiahmad4689/503625234115f21d36285be93e0afd97 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 Baju{ | |
public function buatBaju(); | |
} | |
class BajuLenganPanjang implements Baju{ | |
public function buatBaju() | |
{ | |
echo "Baju Lengan Panjang"; | |
} | |
} | |
class BajuJeans implements Baju{ | |
public function buatBaju() | |
{ | |
echo "Baju Jeans"; | |
} | |
} | |
class BajuLenganPendek implements Baju{ | |
public function buatBaju() | |
{ | |
echo "Baju Lengan Pendek"; | |
} | |
} | |
abstract class PembuatBaju | |
{ | |
abstract function produksi() : Baju; | |
} | |
class Adi extends PembuatBaju | |
{ | |
public function produksi(): Baju | |
{ | |
return new BajuLenganPendek; | |
} | |
} | |
class Herman extends PembuatBaju | |
{ | |
public function produksi(): Baju | |
{ | |
return new BajuJeans; | |
} | |
} | |
$herman = new Herman(); | |
$herman->produksi()->buatBaju(); | |
// output = Baju Jeans | |
echo"<br>"; | |
$adi = new Adi(); | |
$adi->produksi()->buatBaju(); | |
// output = Baju Lengan Pendek | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment