-
Notifications
You must be signed in to change notification settings - Fork 0
/
object-type.php
43 lines (35 loc) · 908 Bytes
/
object-type.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class Produk
{
public $judul,
$penulis,
$penerbit,
$harga;
public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0)
{
$this->judul = $judul;
$this->penulis = $penulis;
$this->penerbit = $penerbit;
$this->harga = $harga;
}
public function getLabel()
{
return "$this->penulis, $this->penerbit";
}
}
class CetakInfoProduk
{
public function cetak(Produk $produk)
{
$str = "{$produk->judul} | {$produk->getLabel()} (Rp. {$produk->harga})";
return $str;
}
}
$produk1 = new Produk("Naruto", "Masashi Kishimoto", "Shonnen Jump", 30000);
$produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer", 250000);
echo "Komik : " . $produk1->getLabel();
echo "<br>";
echo "Game : " . $produk2->getLabel();
echo "<br>";
$infoProduk = new CetakInfoProduk();
echo $infoProduk->cetak($produk1);