Last active
May 30, 2018 06:54
-
-
Save nahidulhasan/f18e9d99d8345bde138cd3943977b090 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 AreaInterface | |
{ | |
public function calculateArea(); | |
} | |
class Rectangle implements AreaInterface | |
{ | |
public $width; | |
public $height; | |
public function __construct($width, $height) | |
{ | |
$this->width = $width; | |
$this->height = $height; | |
} | |
public function calculateArea(){ | |
$area = $this->height * $this->width; | |
return $area; | |
} | |
} | |
class Circle implements AreaInterface | |
{ | |
public $radius; | |
public function __construct($radius) | |
{ | |
$this->radius = $radius; | |
} | |
public function calculateArea(){ | |
$area = $this->radius * $this->radius * pi(); | |
return $area; | |
} | |
} | |
class CostManager | |
{ | |
public function calculate(AreaInterface $shape) | |
{ | |
$costPerUnit = 1.5; | |
$totalCost = $costPerUnit * $shape->calculateArea(); | |
return $totalCost; | |
} | |
} | |
$circle = new Circle(5); | |
$obj = new CostManager(); | |
echo $obj->calculate($circle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment