Skip to content

Instantly share code, notes, and snippets.

@joaorobertopb
Last active January 4, 2019 03:05
Show Gist options
  • Save joaorobertopb/055ece5cbbc7805c3d73b8552e7af8bb to your computer and use it in GitHub Desktop.
Save joaorobertopb/055ece5cbbc7805c3d73b8552e7af8bb to your computer and use it in GitHub Desktop.
Exemplo em PHP da violação do princípio Aberto-Fechado ( Open-Closed ) do SOLID
<?php
class ContratoClt
{
public function salario()
{
//...
}
}
class Estagio
{
public function bolsaAuxilio()
{
//...
}
}
class FolhaDePagamento
{
protected $saldo;
public function calcular($funcionario)
{
if ( $funcionario instanceof ContratoClt ) {
$this->saldo = $funcionario->salario();
} else if ( $funcionario instanceof Estagio) {
$this->saldo = $funcionario->bolsaAuxilio();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment