Last active
August 29, 2015 14:25
-
-
Save alanwillms/d527b33f48e432a34ddd 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 ProdutoImportado extends Produto | |
| { | |
| ... | |
| } | |
| 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(); | |
| if ($item instanceof ProdutoImportado) { | |
| $this->valor_impostos += $item->getValorII(); | |
| } | |
| } 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