Last active
August 29, 2015 14:27
-
-
Save alanwillms/9f6dd5f28f6060a59c3b to your computer and use it in GitHub Desktop.
liskov-breaking-2.php
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 Logger | |
| { | |
| public function log($mensagem) | |
| { | |
| $this->append($mensagem); | |
| } | |
| } | |
| class DatabaseLogger extends Logger // sub-classe | |
| { | |
| public function log($mensagem) // sobrescreve o método Logger::log($mensagem) | |
| { | |
| if (empty($this->database) || !$this->database->isConnected()) { | |
| throw new DbConnectionError; // exceção que não existe na classe-mãe | |
| } | |
| $this->database->insert('log', ['message' => $mensagem]); | |
| } | |
| } | |
| $fileLogger->log('Não foi possível enviar o pedido.'); | |
| # true | |
| $databaseLogger->log('Não foi possível enviar o pedido.'); | |
| # PHP Warning: Uncaught exception 'DbConnectionError' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment