-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_inheritance.php
75 lines (53 loc) · 1.66 KB
/
2_inheritance.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class ShopProduct {
public $title;
public $producerMainName;
public $producerFirstName;
public $price;
public $numPages;
public $playLength;
public function __construct( $title, $firstName, $mainName, $price, $numPages = 0, $playLength = 0 ) {
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
$this->numPages = $numPages;
$this->playLength = $playLength;
}
public function getProducer() {
return "{$this->producerFirstName}" . " {$this->producerMainName}";
}
public function getSummaryLine() {
$base = "$this->title ( {$this->producerMainName}, ";
$base .= "{$this->producerFirstName} )";
return $base;
}
}
class CdProduct extends ShopProduct {
public function getPlayLength() {
return $this->playLength;
}
public function getSummaryLine() {
$base = "{$this->title} ( {$this->producerMainName}, ";
$base .= "{$this->producerFirstName} )";
$base .= ": playing time - {$this->playLength}";
return $base;
}
}
class BookProduct extends ShopProduct {
public function getNumberOfPages() {
return $this->numPages;
}
public function getSummaryLine() {
$base = "{$this->title} ( {$this->producerMainName}, ";
$base .= "{$this->producerFirstName} )";
$base .= ": page count - {$this->numPages}";
return $base;
}
}
$product1 = new CdProduct( "Exile on Coldharbour Lane", "The", "Alabama 3", 10.99, null, 60.33 );
print "artist: {$product1->getProducer()}\n";
echo "<hr>";
$product2 = new BookProduct( "My Antonia", "Willa", "Cather", 5.75, null, 20.23 );
print "artist: {$product2->getProducer()}\n";
?>