Skip to content

Commit 6abfe90

Browse files
authored
Merge pull request mouredev#4942 from miguelex/main
#29 - php
2 parents aca40a3 + b1c112e commit 6abfe90

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
// Ejemplo basico sin ISP
4+
5+
interface PaymentInterface {
6+
public function payOnline($amount);
7+
public function payInCash($amount);
8+
}
9+
10+
class OnlinePayment implements PaymentInterface {
11+
public function payOnline($amount) {
12+
echo "Procesando el pago online de " . $amount . "\n";
13+
}
14+
15+
public function payInCash($amount) {
16+
throw new Exception("El pago Online no admite el pago en efectivo");
17+
}
18+
}
19+
20+
class CashPayment implements PaymentInterface {
21+
public function payOnline($amount) {
22+
throw new Exception("El pago en efectivo no permite el pago por medios online");
23+
}
24+
25+
public function payInCash($amount) {
26+
echo "Procesando el pago en efectivo de " . $amount. "\n";
27+
}
28+
}
29+
30+
echo "\n Ejemplo basico sin ISP\n";
31+
$onlinePayment = new OnlinePayment();
32+
$cashPayment = new CashPayment();
33+
34+
$onlinePayment->payOnline(100);
35+
//$onlinePayment->payInCash(100);
36+
37+
//$cashPayment->payOnline(100);
38+
$cashPayment->payInCash(100);
39+
40+
// Ejemplo basico aplicando ISP
41+
42+
interface OnlinePaymentInterface {
43+
public function payOnline($amount);
44+
}
45+
46+
interface CashPaymentInterface {
47+
public function payInCash($amount);
48+
}
49+
50+
class OnlinePayment2 implements OnlinePaymentInterface {
51+
public function payOnline($amount) {
52+
echo "Procesando el pago online de " . $amount. "\n";
53+
}
54+
}
55+
56+
class CashPayment2 implements CashPaymentInterface {
57+
public function payInCash($amount) {
58+
echo "Procesando el pago en efectivo de " . $amount. "\n";
59+
}
60+
}
61+
62+
echo "\n Ejemplo basico con ISP\n";
63+
$onlinePayment = new OnlinePayment2();
64+
$cashPayment = new CashPayment2();
65+
66+
$onlinePayment->payOnline(100);
67+
68+
$cashPayment->payInCash(100);
69+
70+
// Extra
71+
72+
interface BlackAndWhitePrintInterface {
73+
public function printBlackAndWhite($document);
74+
}
75+
76+
interface ColorPrintInterface {
77+
public function printColor($document);
78+
}
79+
80+
interface ScanInterface {
81+
public function scan($document);
82+
}
83+
84+
interface FaxInterface {
85+
public function sendFax($document);
86+
}
87+
88+
class BlackAndWhitePrinter implements BlackAndWhitePrintInterface {
89+
public function printBlackAndWhite($document) {
90+
echo "Imprimiendo el documento " . $document . " en ByN\n";
91+
}
92+
}
93+
94+
class ColorPrinter implements ColorPrintInterface {
95+
public function printColor($document) {
96+
echo "Imprimiendo el documento " . $document . " en color\n";
97+
}
98+
}
99+
100+
class MultifunctionPrinter implements BlackAndWhitePrintInterface, ColorPrintInterface, ScanInterface, FaxInterface {
101+
public function printBlackAndWhite($document) {
102+
echo "Imprimiendo el documento " . $document . " en ByN\n";
103+
}
104+
105+
public function printColor($document) {
106+
echo "Imprimiendo el documento " . $document . " en color\n";
107+
}
108+
109+
public function scan($document) {
110+
echo "Escaneando el documento " . $document . "\n";
111+
}
112+
113+
public function sendFax($document) {
114+
echo "Mandando por fax el documento ". $document . "\n";
115+
}
116+
}
117+
118+
function testPrinter(BlackAndWhitePrintInterface $bwPrinter = null, ColorPrintInterface $colorPrinter = null, ScanInterface $scanner = null, FaxInterface $faxMachine = null) {
119+
$document = "Test_Document.doc";
120+
121+
if ($bwPrinter !== null) {
122+
$bwPrinter->printBlackAndWhite($document);
123+
}
124+
125+
if ($colorPrinter !== null) {
126+
$colorPrinter->printColor($document);
127+
}
128+
129+
if ($scanner !== null) {
130+
$scanner->scan($document);
131+
}
132+
133+
if ($faxMachine !== null) {
134+
$faxMachine->sendFax($document);
135+
}
136+
}
137+
138+
$bwPrinter = new BlackAndWhitePrinter();
139+
$colorPrinter = new ColorPrinter();
140+
$multifunctionPrinter = new MultifunctionPrinter();
141+
142+
echo "\nExtra\n";
143+
echo "Probando impresora ByN:\n";
144+
testPrinter($bwPrinter);
145+
146+
echo "\nProbanco impresora color:\n";
147+
testPrinter(null, $colorPrinter);
148+
149+
echo "\nProbando impresora multifunción:\n";
150+
testPrinter($multifunctionPrinter, $multifunctionPrinter, $multifunctionPrinter, $multifunctionPrinter);

0 commit comments

Comments
 (0)