Last active
August 29, 2015 14:25
-
-
Save alanwillms/e831f5d7de2d2b5aca6a to your computer and use it in GitHub Desktop.
Open/Closed Principle EXAMPLE
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 Impostometro | |
| { | |
| ... | |
| /** | |
| * Adiciona o valor dos impostos de um item | |
| * @param mixed $item | |
| * @return void | |
| */ | |
| public function somar($item) | |
| { | |
| if ($item instanceof Produto) { | |
| $this->valor_impostos += $item->getValorICMS(); | |
| } elseif ($item instanceof Servico) { | |
| $this->valor_impostos += $item->getValorISS(); | |
| } else { | |
| throw new NotImplementedException('Não é possível calcular os impostos de "' . $item::CLASS . '"'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment