Skip to content

Instantly share code, notes, and snippets.

@nahidulhasan
Last active May 30, 2018 06:54
Show Gist options
  • Save nahidulhasan/f18e9d99d8345bde138cd3943977b090 to your computer and use it in GitHub Desktop.
Save nahidulhasan/f18e9d99d8345bde138cd3943977b090 to your computer and use it in GitHub Desktop.
<?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