Last active
May 30, 2018 06:56
-
-
Save nahidulhasan/75dd7f478c51b6e17494f287207d1b4f 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 | |
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