Created
July 23, 2020 05:05
-
-
Save austinbenerdy/9f99b456f9767a3344cd69962e0af736 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
<?php | |
namespace OrdinaryEngineer\CodeExamples\DependencyInversionPrinciple\GoodExample; | |
class PlayerCharacter | |
{ | |
private IToolInterface $tool; | |
public function __construct(IToolInterface $startingTool) | |
{ | |
$this->tool = $startingTool; | |
} | |
public function useTool() :void | |
{ | |
$this->tool->use(); | |
} | |
public function swapTool(IToolInterface $newTool) :void | |
{ | |
$this->tool = $newTool; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment