Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 23, 2023 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/def8678faff1e1952e7ad43b70f1b6da to your computer and use it in GitHub Desktop.
Save mcsee/def8678faff1e1952e7ad43b70f1b6da to your computer and use it in GitHub Desktop.
<?
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