Last active
August 23, 2023 13:35
-
-
Save mcsee/def8678faff1e1952e7ad43b70f1b6da to your computer and use it in GitHub Desktop.
This file contains 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
<? | |
interface ElectronicDevice { } | |
interface PhoneCommunication { } | |
final class IPad implements ElectronicDevice { | |
private $operatingSystem; // The attributes are duplicated | |
private $battery; | |
// If you have too much duplicated behavior you should extract them | |
public function __construct(Battery $battery, OperatingSystem $ios) { | |
$this->operatingSystem = $ios; | |
$this->battery = $battery; | |
} | |
} | |
final class IPhone implements ElectronicDevice, PhoneCommunication { | |
private $phoneModule; | |
private $operatingSystem; | |
private $battery; | |
public function __construct( | |
Battery $battery, | |
OperatingSystem $ios, | |
PhoneModule $phoneModule) { | |
$this->phoneModule = $phoneModule; | |
$this->operatingSystem = $ios; | |
$this->battery = $battery; | |
} | |
} | |
final class Iphone implements ElectronicDevice, PhoneCommunication { | |
private $phoneModule; | |
private $operatingSystem; | |
private $battery; | |
public function __construct( | |
Battery $battery, | |
OperatingSystem $ios, | |
PhoneModule $phoneModule) { | |
$this->phoneModule = $phoneModule; | |
$this->operatingSystem = $ios; | |
$this->battery = $battery; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment