Created
February 6, 2015 00:50
-
-
Save sbuzonas/e8452798c7473449c94f to your computer and use it in GitHub Desktop.
CommandInterface suggestion
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
abstract class InstallationCommand extends Command | |
{ | |
abstract public function install(); | |
} | |
class MyInstaller extends InstallationCommand | |
{ | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class ThirdPartyCommand extends Command {} | |
class ThirdPartyInstaller extends InstallationCommand | |
{ | |
// a bunch of methods copy pasted from ThirdPartyCommand | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class InstallerConsumingCommand extends Command { | |
public function addInstaller(InstallationCommand $installer) { | |
$this->installers[] = $installer; | |
} | |
} |
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
interface InstallationCommandInterface extends CommandInterface | |
{ | |
public function install(); | |
} | |
class MyInstaller extends Command implements InstallationCommandInterface | |
{ | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class ThirdPartyCommand extends Command {} | |
class ThirdPartyInstaller extends ThirdPartyCommand implements InstallationCommandInterface | |
{ | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class InstallerConsumingCommand extends Command { | |
public function addInstaller($installer) { | |
if (!($installer instanceof Command && $installer instanceof InstallationCommandInterface)) { | |
throw new \InvalidArgumentException('You need to extend Command and implement InstallationCommandInterface'); | |
} | |
$this->installers[] = $installer; | |
} | |
} |
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
interface InstallationCommandInterface extends CommandInterface | |
{ | |
public function install(); | |
} | |
class MyInstaller extends Command implements InstallationCommandInterface | |
{ | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class ThirdPartyCommand extends Command {} | |
class ThirdPartyInstaller extends ThirdPartyCommand implements InstallationCommandInterface | |
{ | |
public function install() | |
{ | |
// do stuff | |
} | |
} | |
class InstallerConsumingCommand extends Command { | |
public function addInstaller(InstallationCommandInterface $installer) { | |
$this->installers[] = $installer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment