Skip to content

Instantly share code, notes, and snippets.

@taufikherjanto
Created October 3, 2016 09:24
Show Gist options
  • Save taufikherjanto/35f0d7f425104a310b602693e289a055 to your computer and use it in GitHub Desktop.
Save taufikherjanto/35f0d7f425104a310b602693e289a055 to your computer and use it in GitHub Desktop.
<?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