forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiguelex.php
150 lines (113 loc) · 3.85 KB
/
miguelex.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// Ejemplo basico sin ISP
interface PaymentInterface {
public function payOnline($amount);
public function payInCash($amount);
}
class OnlinePayment implements PaymentInterface {
public function payOnline($amount) {
echo "Procesando el pago online de " . $amount . " €\n";
}
public function payInCash($amount) {
throw new Exception("El pago Online no admite el pago en efectivo");
}
}
class CashPayment implements PaymentInterface {
public function payOnline($amount) {
throw new Exception("El pago en efectivo no permite el pago por medios online");
}
public function payInCash($amount) {
echo "Procesando el pago en efectivo de " . $amount. " €\n";
}
}
echo "\n Ejemplo basico sin ISP\n";
$onlinePayment = new OnlinePayment();
$cashPayment = new CashPayment();
$onlinePayment->payOnline(100);
//$onlinePayment->payInCash(100);
//$cashPayment->payOnline(100);
$cashPayment->payInCash(100);
// Ejemplo basico aplicando ISP
interface OnlinePaymentInterface {
public function payOnline($amount);
}
interface CashPaymentInterface {
public function payInCash($amount);
}
class OnlinePayment2 implements OnlinePaymentInterface {
public function payOnline($amount) {
echo "Procesando el pago online de " . $amount. " €\n";
}
}
class CashPayment2 implements CashPaymentInterface {
public function payInCash($amount) {
echo "Procesando el pago en efectivo de " . $amount. " €\n";
}
}
echo "\n Ejemplo basico con ISP\n";
$onlinePayment = new OnlinePayment2();
$cashPayment = new CashPayment2();
$onlinePayment->payOnline(100);
$cashPayment->payInCash(100);
// Extra
interface BlackAndWhitePrintInterface {
public function printBlackAndWhite($document);
}
interface ColorPrintInterface {
public function printColor($document);
}
interface ScanInterface {
public function scan($document);
}
interface FaxInterface {
public function sendFax($document);
}
class BlackAndWhitePrinter implements BlackAndWhitePrintInterface {
public function printBlackAndWhite($document) {
echo "Imprimiendo el documento " . $document . " en ByN\n";
}
}
class ColorPrinter implements ColorPrintInterface {
public function printColor($document) {
echo "Imprimiendo el documento " . $document . " en color\n";
}
}
class MultifunctionPrinter implements BlackAndWhitePrintInterface, ColorPrintInterface, ScanInterface, FaxInterface {
public function printBlackAndWhite($document) {
echo "Imprimiendo el documento " . $document . " en ByN\n";
}
public function printColor($document) {
echo "Imprimiendo el documento " . $document . " en color\n";
}
public function scan($document) {
echo "Escaneando el documento " . $document . "\n";
}
public function sendFax($document) {
echo "Mandando por fax el documento ". $document . "\n";
}
}
function testPrinter(BlackAndWhitePrintInterface $bwPrinter = null, ColorPrintInterface $colorPrinter = null, ScanInterface $scanner = null, FaxInterface $faxMachine = null) {
$document = "Test_Document.doc";
if ($bwPrinter !== null) {
$bwPrinter->printBlackAndWhite($document);
}
if ($colorPrinter !== null) {
$colorPrinter->printColor($document);
}
if ($scanner !== null) {
$scanner->scan($document);
}
if ($faxMachine !== null) {
$faxMachine->sendFax($document);
}
}
$bwPrinter = new BlackAndWhitePrinter();
$colorPrinter = new ColorPrinter();
$multifunctionPrinter = new MultifunctionPrinter();
echo "\nExtra\n";
echo "Probando impresora ByN:\n";
testPrinter($bwPrinter);
echo "\nProbanco impresora color:\n";
testPrinter(null, $colorPrinter);
echo "\nProbando impresora multifunción:\n";
testPrinter($multifunctionPrinter, $multifunctionPrinter, $multifunctionPrinter, $multifunctionPrinter);