-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesignPatternFactory.php
67 lines (50 loc) · 1.16 KB
/
designPatternFactory.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
<?php
abstract class IceCream {
public function getType(){
echo $this->type;
}
}
class Raffi extends IceCream{
private $type = "Raffi";
public function getType(){
echo $this->type;
}
}
class Delta extends IceCream{
private $type = "Delta";
public function getType(){
echo $this->type;
}
}
class Darko extends IceCream{
private $type = "Darko";
public function getType(){
echo $this->type;
}
}
class IceCreamFactory {
const RAFFI = "Raffi";
const DELTA = "Delta";
const DARKO = "Darko";
public static function createIceCream($iceCreamType){
switch($iceCreamType){
case self::RAFFI:
return new Raffi();
break;
case self::DELTA:
return new Delta();
break;
case self::DARKO:
return new Darko();
}
die("IceCream isn't recognized.");
}
}
$iceCreamFactory = new IceCreamFactory();
$Raffi = $iceCreamFactory->createIceCream(IceCreamFactory::RAFFI);
$Raffi->getType();
$Delta = $iceCreamFactory->createIceCream(IceCreamFactory::DELTA);
$Delta->getType();
$Darko = $iceCreamFactory->createIceCream(IceCreamFactory::DARKO);
$Darko->getType();
?>