Skip to content

Instantly share code, notes, and snippets.

@joaorobertopb
Created January 5, 2019 01:23
Show Gist options
  • Save joaorobertopb/d2e04d9a69c822f125cf021656725695 to your computer and use it in GitHub Desktop.
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.
<?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