Created
January 4, 2019 20:21
-
-
Save joaorobertopb/a0478b9daa7da7bdbdc0d5fb903fea90 to your computer and use it in GitHub Desktop.
Exemplos em PHP de violação do princípio de Liskov do SOLID.
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 | |
# - Sobrescrevendo um método que não faz nada... | |
class Voluntario extends ContratoDeTrabalho | |
{ | |
public function remuneracao() | |
{ | |
// não faz nada | |
} | |
} | |
# - Lançando uma exceção inesperada... | |
class MusicPlay | |
{ | |
public function play($file) | |
{ | |
// toca a música | |
} | |
} | |
class Mp3MusicPlay extends MusicPlay | |
{ | |
public function play($file) | |
{ | |
if (pathinfo($file, PATHINFO_EXTENSION) !== 'mp3') { | |
throw new Exception; | |
} | |
// toca a música | |
} | |
} | |
# - Retornando valores de tipos diferentes... | |
class Auth | |
{ | |
public function checkCredentials($login, $password) | |
{ | |
// faz alguma coisa | |
return true; | |
} | |
} | |
class AuthApi extends Auth | |
{ | |
public function checkCredentials($login, $password) | |
{ | |
// faz alguma coisa | |
return ['auth' => true, 'status' => 200]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment