Skip to content

Instantly share code, notes, and snippets.

@alanwillms
Last active August 29, 2015 14:25
Show Gist options
  • Save alanwillms/e831f5d7de2d2b5aca6a to your computer and use it in GitHub Desktop.
Save alanwillms/e831f5d7de2d2b5aca6a to your computer and use it in GitHub Desktop.
Open/Closed Principle EXAMPLE
<?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