Hi;
I found some code in Laracast website that does not make sense to me. He is trying to explain OCP (open close prncipals).
Why is he even creating area_calculator class? square class is doing everything anyway, isn’t it? I think the whole area_calculator can just go.
interface shape
{
public function area();
}
class square implements shape
{
public $width;
public $height;
public function __construct($width, $height)
{
$this->height = $height;
$this->width = $width;
}
public function area()
{
return $this->width * $this->height;
}
}
class area_calculator
{
public function calculates($shape)
{
foreach($shapes as $shape)
{
$area[] = $shape->area();
}
return array_sum($area);
}
}