Created
October 3, 2016 09:24
-
-
Save taufikherjanto/35f0d7f425104a310b602693e289a055 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 Hitung { | |
public function calculate(); | |
} | |
class Jumlah implements Hitung | |
{ | |
private $a; | |
private $b; | |
public function __construct($a, $b) { | |
$this->a = $a; | |
$this->b = $b; | |
} | |
public function calculate() { | |
return $this->a + $this->b; | |
} | |
} | |
class Kali implements Hitung | |
{ | |
private $a; | |
private $b; | |
public function __construct($a, $b) { | |
$this->a = $a; | |
$this->b = $b; | |
} | |
public function calculate() { | |
return $this->a * $this->b; | |
} | |
} | |
class Kurang implements Hitung | |
{ | |
private $a; | |
private $b; | |
public function __construct($a, $b) { | |
$this->a = $a; | |
$this->b = $b; | |
} | |
public function calculate() { | |
return $this->a - $this->b; | |
} | |
} | |
$jumlah = new Jumlah(20, 10); | |
$kali = new Kali(20, 10); | |
$kurang = new Kurang(20, 10); | |
echo $jumlah->calculate(); | |
echo PHP_EOL; | |
echo $kali->calculate(); | |
echo PHP_EOL; | |
echo $kurang->calculate(); | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment