دولوپری که نداند Polymorphism چیست، دولوپر نیست!
interface Shape {
public function calcArea();
}
حال اقدام به نوشتن کلاس مربوط به دایره میکنیم که اینترفیس فوقالذکر روی آن اعمال شده است:
class Circle implements Shape {
private $radius;
public function __construct($radius) {
$this->radius = $radius;
}
// calcArea calculates the area of circles
public function calcArea() {
return $this->radius * $this->radius * pi();
}
}Last updated