-
[객체지향PHP]8.Interface서버/PHP 2020. 11. 6. 08:16
Interface 는 클래스의 설계 도면을 만든다고 보면 된다.
<?php interface Paymentinterface{ public function payNow(); } interface LoginInterface{ public function LoginFirst(); } class Paypal implements PaymentInterface,LoginInterface{ public function loginFirst(){} public function payNow(){} public function paymentProcess(){ $this->loginFirst(); $this->payNow(); } } class BankTransfer implements PaymentInterface,LoginInterface{ public function loginFirst(){} public function payNow(){} public function paymentProcess(){ $this->loginFirst(); $this->payNow(); } } class Visa implements PaymentInterface{ public function payNow(){} public function paymentProcess(){ $this->PayNow(); } } class Cash implements PaymentInterface{ public function payNow(){} public function paymentProcess(){ $this->PayNow(); } } class BuyProduct{ public function pay(PaymentInterface $paymentType){ $paymentType->paymentProcess(); } public function onlinePay(LoginInterface $paymentType){ $paymentType->paymentProcess(); } } $paymentType=new Cash(); $buyProduct=new BuyProduct(); $buyProduct->pay($paymentType); ?>
'서버 > PHP' 카테고리의 다른 글
class-autoload.inc.php (0) 2020.12.10 PDO:: (0) 2020.11.06 Type Declaration (0) 2020.11.05 [객체지향PHP]7.Namespace (0) 2020.11.05 [객체지향PHP]6.include (0) 2020.11.05