Created
November 19, 2019 14:00
-
-
Save fabioars/15ffc6ddee0cb37e2c2dd238c0df66f5 to your computer and use it in GitHub Desktop.
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 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