Skip to content

Instantly share code, notes, and snippets.

@nahidulhasan
Last active May 30, 2018 06:56
Show Gist options
  • Save nahidulhasan/75dd7f478c51b6e17494f287207d1b4f to your computer and use it in GitHub Desktop.
Save nahidulhasan/75dd7f478c51b6e17494f287207d1b4f to your computer and use it in GitHub Desktop.
<?php
class Rectangle
{
public $width;
public $height;
public function __construct($width, $height)
{
$this->width = $width;
$this->height = $height;
}
}
class Circle
{
public $radius;
public function __construct($radius)
{
$this->radius = $radius;
}
}
class CostManager
{
public function calculate($shape)
{
$costPerUnit = 1.5;
if ($shape instanceof Rectangle) {
$area = $shape->width * $shape->height;
} else {
$area = $shape->radius * $shape->radius * pi();
}
return $costPerUnit * $area;
}
}
$circle = new Circle(5);
$rect = new Rectangle(8,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