Created
March 13, 2019 21:42
-
-
Save hopeseekr/f819390c6178f896d0e40e4f2330fe5d to your computer and use it in GitHub Desktop.
Strategy Pattern Educational Code
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 | |
interface RESTAuthDriver | |
{ | |
public function setApiClient(RESTSpeaker $apiClient); | |
public function generateGuzzleAuthOptions(): array; | |
} | |
interface Foo2 | |
{ | |
public function hi(); | |
} | |
abstract class Foo | |
{ | |
// public function hi() { echo "Hi\n"; } | |
abstract protected function hi(); | |
public function greet() | |
{ | |
echo $this->hi(); | |
} | |
} | |
$realFoo = new class extends Foo | |
{ | |
protected function hi() | |
{ | |
echo "Foo\n"; | |
} | |
}; | |
class Bar extends Foo | |
{ | |
protected function hi() | |
{ | |
echo "Bar\n"; | |
} | |
} | |
$hiStrategy = 'BarZ'; | |
(new $hiStrategy)->greet(); | |
$realFoo->greet(); | |
(new Bar())->greet(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment