-
-
Save stephandesouza/57437e09fbab3a6b9e0a 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 Atendimento | |
{ | |
const SUPORTE = 1; | |
const FINANCEIRO = 2; | |
const ADMINISTRATIVO = 3; | |
public function encerrar(); | |
} | |
class Suporte implements Atendimento | |
{ | |
public function encerrar() | |
{ | |
return "Encerrar Suporte"; | |
} | |
} | |
class Financeiro implements Atendimento | |
{ | |
public function encerrar() | |
{ | |
return "Encerrar Financeiro"; | |
} | |
} | |
class Administrativo implements Atendimento | |
{ | |
public function encerrar() | |
{ | |
return "Encerrar Administrativo"; | |
} | |
} | |
class AtendimentoFactory | |
{ | |
public static $atendimentoClass = [ | |
1 => 'Suporte', | |
'Financeiro', | |
'Administrativo' | |
]; | |
public static function createAtendimentoPorTipo($tipo) | |
{ | |
if(!isset(self::$atendimentoClass[$tipo])) { | |
throw new \OutOfBoundsException('Tipo de atendimento não encontrado.'); | |
} | |
return new self::$atendimentoClass[$tipo]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Foi solicitado o não uso de Switch..
Nesse formato você pode saber qual a classe responsável usando AtendimentoFactory::$atendimentoClass
Complementei colocando um Exception caso o cara informe um tipo não esperado