Created
November 23, 2018 12:51
-
-
Save domzgarcia/04bd0f1f32c1813c38f6be82ac7227e8 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 | |
class Pokemon | |
{ | |
public function attack() | |
{ | |
echo 'Punch'; | |
} | |
public function rest() | |
{ | |
echo 'Sleep'; | |
} | |
} | |
class Pikachu extends Pokemon | |
{ | |
public function attack() | |
{ | |
echo 'Lightning!'; | |
} | |
public function duplicate() | |
{ | |
echo '2x'; | |
} | |
} | |
class Squerrel extends Pokemon | |
{ | |
public function attack() | |
{ | |
echo 'Water ball!'; | |
} | |
public function rest() | |
{ | |
echo 'Self destroy!'; | |
} | |
} | |
class PokemonFactory | |
{ | |
public function build($name) | |
{ | |
return new $name(); | |
} | |
} | |
class Trainer | |
{ | |
protected $pokemon; | |
public function usePokemonBaseOnElementType($type) | |
{ | |
$factory = new PokemonFactory(); | |
if ($type == 'light') { | |
$this->setPokemon($factory->build('Pikachu')); | |
} elseif ($type == 'water') { | |
$this->setPokemon($factory->build('Squerrel')); | |
} | |
} | |
public function setPokemon(Pokemon $pokemon) | |
{ | |
$this->pokemon = $pokemon; | |
} | |
public function useYourSkill() | |
{ | |
$this->pokemon->attack(); | |
} | |
public function pleaseRest() | |
{ | |
$this->pokemon->rest(); | |
} | |
public function doYourBest() | |
{ | |
return $this->pokemon; | |
} | |
} | |
$trainer = new Trainer(); | |
$trainer->usePokemonBaseOnElementType('light'); | |
$trainer->useYourSkill(); | |
$trainer->pleaseRest(); | |
$trainer->doYourBest()->duplicate(); | |
class ATMFacade | |
{ | |
public static function checkBalance() | |
{ | |
return CheckBalanceBuilder(); | |
} | |
public static function deposit() | |
{ | |
} | |
public static function withdraw() | |
{ | |
} | |
} | |
echo ATMFacade::checkBalance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment