-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
60 lines (53 loc) · 1.25 KB
/
template.php
File metadata and controls
60 lines (53 loc) · 1.25 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
<?php
/*
Template pattern:
template is a preset format, used as a starting point for a particular application
A template method defines an algorithm in a base class using abstract operations
that subclasses override to provide concrete behavior.
*/
abstract class TripPackage {
public final function doTrip() {
$this->startTrip();
$this->dayOne();
$this->dayTwo();
$this->endTrip();
}
abstract public function startTrip();
abstract public function dayOne();
abstract public function dayTwo();
abstract public function endTrip();
}
class PackageA extends TripPackage {
public function startTrip() {
print "Start in Airport\n";
}
public function dayOne() {
print "Take cruise\n";
}
public function dayTwo() {
print "Take Bus\n";
}
public function endTrip() {
print "Arrive in Airport\n";
}
}
class PackageB extends TripPackage {
public function startTrip() {
print "Start in Puerta Vallarta\n";
}
public function dayOne() {
print "Dock in Cancun\n";
}
public function dayTwo() {
print "Dock in Cozumel\n";
}
public function endTrip() {
print "Arrive Back at Home Airport\n";
}
}
$trip = new PackageA;
$trip->doTrip();
print "\n\n";
$trip2 = new PackageB;
$trip2->doTrip();
?>