Created
April 17, 2024 09:16
-
-
Save sonus/62db6a40b41f0fd6b3445b7c1e426f8b to your computer and use it in GitHub Desktop.
Depend on Abstractions, not Concretions (Framework)
This file contains hidden or 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 | |
abstract class Player { | |
public abstract function play(); | |
} | |
class Human extends Player { | |
public function play() { | |
echo "Human player makes a move.\n"; | |
} | |
} | |
class Computer extends Player { | |
public function play() { | |
echo "Computer player makes a move.\n"; | |
} | |
} | |
class Round { | |
private Player $player1; | |
private Player $player2; | |
public function __construct(Player $player1, Player $player2) { | |
$this->player1 = $player1; | |
$this->player2 = $player2; | |
} | |
public function playRound() { | |
$this->player1->play(); | |
$this->player2->play(); | |
echo "Determine winner or tie based on game rules.\n"; | |
} | |
} | |
$humanPlayer = new Human(); | |
$computerPlayer = new Computer(); | |
$round = new Round($humanPlayer, $computerPlayer); | |
$round->playRound(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment