Created
June 17, 2020 06:08
-
-
Save aginanjar/2e9da21cb975d724bd07838515559e11 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 Phone { | |
public function turnOn(); | |
} | |
class PhoneUser { | |
private $phone; | |
public function __construct(Phone $phone) { | |
$this->phone = $phone; | |
} | |
public function turnOn() { | |
$this->phone->turnOn(); | |
} | |
} | |
class Xiaomi implements Phone { | |
private $xiaomi; | |
public function turnOn() { | |
echo " Xiaomi: ON"; | |
} | |
} | |
class Iphone implements Phone { | |
private $xiaomi; | |
public function turnOn() { | |
echo " Iphone: ON"; | |
} | |
} | |
$x = new Xiaomi(); | |
$i = new Iphone(); | |
$xUser = new PhoneUser($x); | |
$xUser->turnOn(); | |
$iUser = new PhoneUser($i); | |
$iUser->turnOn(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment