-
Notifications
You must be signed in to change notification settings - Fork 0
/
object-type.php
41 lines (34 loc) · 1.02 KB
/
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
<?php
// Jualan Produk
// Komik
// Game
class Produk {
public $judul,
$penulis,
$penerbit,
$harga = 0;
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", "Shonen Jump", 30000);
$produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer", 250000);
$produk3 = new Produk("Dragon Ball");
echo "Komik : ". $produk1->getLabel();
echo "<br>";
echo "Game : ". $produk2->getLabel();
echo "<br>";
$infoProduk1 = new CetakInfoProduk();
echo $infoProduk1->cetak($produk1);