Last active
May 22, 2020 21:03
-
-
Save PululuK/37794c60d429bd90cc1887d26b021ed3 to your computer and use it in GitHub Desktop.
polymorphisme concept
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
class T | |
{ | |
private $type; | |
public function __construct(A $a) | |
{ | |
$this->setType($a); | |
} | |
public function getType() | |
{ | |
return $this->type->getType(); | |
} | |
public function setType(A $a) | |
{ | |
$this->type = $a; | |
} | |
} | |
interface A | |
{ | |
public function getType(); | |
} | |
class B implements A | |
{ | |
public function getType() | |
{ | |
echo __CLASS__, PHP_EOL; | |
} | |
} | |
class C implements A | |
{ | |
public function getType() | |
{ | |
echo __CLASS__, PHP_EOL; | |
} | |
} | |
$b = new B(); | |
($t = new T($b))->getType(); | |
$c = new C(); | |
$t->setType($c); | |
$t->getType(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment