Created
January 5, 2019 01:23
-
-
Save joaorobertopb/d2e04d9a69c822f125cf021656725695 to your computer and use it in GitHub Desktop.
Exemplo em PHP da utilização do princípio SOLID de substituição de Liskov.
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 | |
class A | |
{ | |
public function getNome() | |
{ | |
echo 'Meu nome é A'; | |
} | |
} | |
class B extends A | |
{ | |
public function getNome() | |
{ | |
echo 'Meu nome é B'; | |
} | |
} | |
$objeto1 = new A; | |
$objeto2 = new B; | |
function imprimeNome(A $objeto) | |
{ | |
return $objeto->getNome(); | |
} | |
imprimeNome($objeto1); // Meu nome é A | |
imprimeNome($objeto2); // Meu nome é B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment