forked from eimg/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23-template.php
49 lines (39 loc) · 845 Bytes
/
23-template.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
<?php
// === A Template for all Car ===
abstract class Car
{
public $color = "White";
public $doors = 4;
public function __construct($name)
{
$this->name = $name;
}
public function loadPassenger()
{
echo "The $this->name is loading passengers...\n";
}
}
class Minivan extends Car
{
public $doors = 5;
public function loadGrocery()
{
echo "The $this->name is loading grocery...\n";
}
}
class SportCar extends Car
{
public $doors = 2;
public $color = "Red";
public function loadPassenger()
{
echo "The $this->name is loading a buddy...\n";
}
}
// ---
$fit = new Minivan("Fit");
$fit->loadPassenger();
// Output: The Fit is loading passengers...
$evo = new SportCar("Evo");
$evo->loadPassenger();
// Output: The Evo is loading a buddy...