Last active
July 18, 2020 16:46
-
-
Save samadfcibd/2904349c7d139a96c6b886176987db23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface paymentInterface | |
{ | |
public function pay(); | |
} | |
class payWithPaypal implements paymentInterface | |
{ | |
public function pay() | |
{ | |
// TODO: Implement pay() method. | |
} | |
} | |
class payWithCreditCard implements paymentInterface | |
{ | |
public function pay() | |
{ | |
// TODO: Implement pay() method. | |
} | |
} | |
class payWithWireTransfer implements paymentInterface | |
{ | |
public function pay() | |
{ | |
// TODO: Implement pay() method. | |
} | |
} | |
class PaymentService | |
{ | |
public function initialize($payment_type) | |
{ | |
switch ($payment_type) { | |
case 'Paypal': | |
return new payWithPaypal(); | |
break; | |
case 'Credit Card': | |
return new payWithCreditCard(); | |
break; | |
default: | |
return new payWithWireTransfer(); | |
} | |
} | |
} | |
class PaymentController | |
{ | |
public function pay(Request $request, PaymentService $paymentService) | |
{ | |
$payment_type = $request->input('payment_type'); | |
// OCP refactor | |
$payment = $paymentService->initialize('Paypal'); | |
$payment->pay(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment