-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_8.php
56 lines (44 loc) · 1.45 KB
/
2_8.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
<?php
// INTERFACES - Group together classes and give them a set of behaviors
interface PaymentInterface{
public function payNow();
}
interface LoginInterface{
public function loginFirst();
}
class PayPal implements PaymentInterface, LoginInterface { // Implements two interfaces
public function loginFirst() {} //only PP requires login first
public function payNow() {}
public function paymentProcess() {
$this->loginFirst();
$this->payNow();
}
}
class BankTransfer implements PaymentInterface, LoginInterface { // Implements two interfaces
public function loginFirst() {} //only PP requires login first
public function payNow() {}
public function paymentProcess() {
$this->loginFirst();
$this->payNow();
}
}
class Visa implements PaymentInterface {
public function paymentProcess() {
$this->payNow();
}
}
class Cache implements PaymentInterface {
public function paymentProcess() {
$this->payNow();
}
}
class BuyProduct {
public function pay (PaymentInterface $paymentType){ // interface acts as mixed type declaration
$paymentType->PaymentProcess();
}
}
$paymentType = new PayPal();
$buyProduct = new BuyProduct();
$buyProduct->paymentProcess($paymentType);
?>
<p>See the <a href="https://www.php.net/manual/en/language.oop5.interfaces.php">documentation</a> & especially for the first note on them which explains bette why we use interfaces.</p>