Skip to content

Instantly share code, notes, and snippets.

@fabioars
Created November 19, 2019 14:00
Show Gist options
  • Save fabioars/15ffc6ddee0cb37e2c2dd238c0df66f5 to your computer and use it in GitHub Desktop.
Save fabioars/15ffc6ddee0cb37e2c2dd238c0df66f5 to your computer and use it in GitHub Desktop.
<?php
interface PagamentoInteface {
public function pagar();
}
interface PegamentoCancelavelInteface extends PagamentoInteface {
public function cancelar();
}
interface PagadorInteface {
public function pagar(PagamentoInteface $pagamento);
}
class PagamentoPagseguro implements PagamentoInteface {
public function pagar() {
// logica pagamento do pag seguro
}
}
class PagamentoRede implements PagamentoInteface {
public function pagar() {
// logica pagamento da rede
}
}
class PagamentoNaEntrega implements PagamentoInteface {
public function pagar() {
// logica pagamento da rede
}
}
class Pagador implements PagadorInterface {
public function pagar(PagamentoInteface $pagamento) {
$pagamento->pagar();
}
}
$pagamentos = [
'erede' => PagamentoRede::class,
'pagseguro' => PagamentoPagSeguro::class,
];
class PagamentoBuilder {
private $pagamento;
public function __constructor($kind) {
$this->pagamento = new $pagamentos[$kind]();
}
public function get() {
return $pagamento;
}
}
$pagamento = (new PagamentoBuilder('erede'))
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment