-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstract_factory.php
49 lines (44 loc) · 1.18 KB
/
abstract_factory.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
/*
switch ($etfType) {
case ETF_VIRTUALCHECK :
$etf = new VirtualCheck();
$etf->processCheck();
break;
case ETF_CREDITCARD :
$etf = new CreditCard();
$etf->chargeCard();
break;
case ETF_WIRETRANSFER :
$etf = new WireTransfer();
$etf->chargeCard();
break;
}
//Read more at http://www.devshed.com/c/a/PHP/Design-Patterns-in-PHP-Factory-Method-and-Abstract-Factory/1/#sKgeCmLSMzI4B5KQ.99
*/
class ETF {
var $data;
function ETF($data) {
$this->data = $data;
}
function process() {}
function getResult() {}
}
class VirtualCheck extends ETF {}
class WireTransfer extends ETF {}
class ETFFactory {
function createETF($data) {
switch ($data['etfType']) {
case ETF_VIRTUALCHECK :
return new VirtualCheck($data);;
case ETF_WIRETRANSFER :
return new WireTransfer($data);
default :
return new ETF($data);
}
}
}
$data = $_POST;
$etf = ETFFactory::createETF($data);
$etf->process();
//Read more at http://www.devshed.com/c/a/PHP/Design-Patterns-in-PHP-Factory-Method-and-Abstract-Factory/1/#sKgeCmLSMzI4B5KQ.99