Skip to content

Instantly share code, notes, and snippets.

@austinbenerdy
Created July 23, 2020 05:05
Show Gist options
  • Save austinbenerdy/9f99b456f9767a3344cd69962e0af736 to your computer and use it in GitHub Desktop.
Save austinbenerdy/9f99b456f9767a3344cd69962e0af736 to your computer and use it in GitHub Desktop.
<?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