Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface GameInterface
- {
- public function checkLevel();
- }
- class Game
- {
- public $game;
- public function __construct(GameInterface $game)
- {
- $this->game = $game;
- }
- public function play()
- {
- $className = get_class($this->game);
- if ($this->game->checkLevel() === true) {
- return "{$className} can play";
- }
- return "{$className} can't play";
- }
- }
- class Mario implements GameInterface
- {
- public function checkLevel()
- {
- return true;
- }
- }
- class Race implements GameInterface
- {
- public function checkLevel()
- {
- return false;
- }
- }
- echo (new Game(new Mario))->play() . PHP_EOL;
- echo (new Game(new Race))->play() . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement