Skip to content

Instantly share code, notes, and snippets.

@aginanjar
Created June 17, 2020 06:08
Show Gist options
  • Save aginanjar/2e9da21cb975d724bd07838515559e11 to your computer and use it in GitHub Desktop.
Save aginanjar/2e9da21cb975d724bd07838515559e11 to your computer and use it in GitHub Desktop.
<?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