Last active
September 21, 2015 17:30
-
-
Save alanwillms/c884e869fa52b1ba5120 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 | |
| interface Tributavel | |
| { | |
| /** | |
| * Calcula o valor dos impostos que incidem sobre esta entidade. | |
| * @return float | |
| */ | |
| public function getValorImpostos(); | |
| } | |
| class Servico implements Tributavel | |
| { | |
| ... | |
| public function getValorImpostos() | |
| { | |
| return $this->getValorISS(); | |
| } | |
| } | |
| class Produto implements Tributavel | |
| { | |
| ... | |
| public function getValorImpostos() | |
| { | |
| return $this->getValorICMS(); | |
| } | |
| } | |
| class ProdutoImportado extends Produto | |
| { | |
| ... | |
| public function getValorImpostos() | |
| { | |
| return parent::getValorImpostos() + $this->getValorII(); | |
| } | |
| } | |
| class Impostometro | |
| { | |
| ... | |
| /** | |
| * Adiciona o valor dos impostos de um item | |
| * @param Tributavel $item | |
| * @return void | |
| */ | |
| public function somar(Tributavel $item) | |
| { | |
| $this->valor_impostos += $item->getValorImpostos(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá
Alan,Na sua interface, o método
getValorImpostos()não precisa usar o modificadorabstract, certo?