/
11-interface.php
56 lines (44 loc) · 950 Bytes
/
11-interface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
interface Shape
{
public function calculateArea();
public function calculatePerimeter();
}
class Circle implements Shape
{
private $radius;
public function __construct($radius)
{
$this->radius = $radius;
}
public function calculateArea()
{
return pi() * $this->radius * $this->radius;
}
public function calculatePerimeter()
{
return 2 * pi() * $this->radius;
}
}
class Rectangle implements Shape
{
private $length;
private $width;
public function __construct($length, $width)
{
$this->length = $length;
$this->width = $width;
}
public function calculateArea()
{
return $this->length * $this->width;
}
public function calculatePerimeter()
{
return 2 * ($this->length + $this->width);
}
}
$shape = new Rectangle(2, 5);
echo $shape->calculateArea();
echo $shape->calculatePerimeter();
?>