-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathShape.php
More file actions
62 lines (49 loc) · 1.52 KB
/
Shape.php
File metadata and controls
62 lines (49 loc) · 1.52 KB
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
57
58
59
60
61
62
<?php
class Shape {
// class constants
const SHAPE_TYPE = 1;
// property declarations
public $name;
protected $length;
protected $width;
private $id;
// method declarations
public function __construct ( $length = 0, $width = 0 ) {
$this->length = $length;
$this->width = $width;
$this->id = uniqid();
}
public function getName() {
return $this->name;
}
public function setName( $name ) {
$this->name = $name;
}
public function getId() {
return $this->id;
}
public function area() {
return $this->length * $this->width;
}
static public function getTypeDescription() {
return "Type: " . static::SHAPE_TYPE;
}
public function getFullDescription() {
switch (static::SHAPE_TYPE) {
case 1: // case of SHAPE
$shapeName = "Shape";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->length . " x " . $this->width;
break;
case 2: // case of RECTANGLE
$shapeName = "Rectangle";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->length . " x " . $this->width;
break;
case 3: // case of CIRCLE
$shapeName = "Circle";
$postfix = "<#" . $this->id . ">: " . $this->name . " - " . $this->radius;
break;
} // end switch
return $shapeName . $postfix;
}
} // end class
?>