Skip to content

Instantly share code, notes, and snippets.

@alanwillms
Last active September 21, 2015 17:30
Show Gist options
  • Save alanwillms/c884e869fa52b1ba5120 to your computer and use it in GitHub Desktop.
Save alanwillms/c884e869fa52b1ba5120 to your computer and use it in GitHub Desktop.
Open/Closed Principle EXAMPLE
<?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();
}
}
@chapeupreto
Copy link

Olá Alan,

Na sua interface, o método getValorImpostos() não precisa usar o modificador abstract, certo?

@alanwillms
Copy link
Author

Certo @chapeupreto 👍 corrigido

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment