Created
July 22, 2020 21:11
-
-
Save allaniftrue/57037155cbedd992b0a123b50f238c9a to your computer and use it in GitHub Desktop.
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 | |
interface Fowl | |
{ | |
public function layEgg() : Egg; | |
} | |
class Egg | |
{ | |
private $hatched; | |
private $type; | |
public function __construct(string $fowlType) | |
{ | |
$this->type = $fowlType; | |
} | |
public function hatch() : ?Fowl | |
{ | |
if ($this->hatched == true) { | |
throw new Exception('Already htached'); | |
} | |
$this->hatched = true; | |
return new $this->type(); | |
} | |
} | |
class Hen implements Fowl | |
{ | |
public function layEgg() : Egg { | |
return new Egg('Hen'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment