<!DOCTYPE html>
<html>
<body>
<?php
class dois_pinos
{
public function getSaida()
{
return "DOIS PINOS";
}
}
interface dois_pinos_interface
{
public function getSaida();
}
class dois_pinos_adapter implements dois_pinos_interface
{
protected $doisPinos;
function __construct(dois_pinos $doisPinos) {
$this->doisPinos = $doisPinos;
}
public function getSaida()
{
if($this->doisPinos->getSaida() == 'DOIS PINOS') {
return 'TRES PINOS';
}
}
}
class receptor_tres_pinos
{
protected $saida = 'TRES PINOS';
public function conectar($entrada)
{
if($entrada == $this->saida) {
return "CONECTADO!";
} else {
return "TIPO DE ENTRADA E RECEPETOR DIFERENTES!";
}
}
public function getSaida()
{
return $this->saida;
}
}
echo "**TENTAR CONECTAR 2 PINOS NA TOMADA 3 PINOS**" . "<br>";
$tomada_dois_pinos = new dois_pinos();
$receptor_tres_pinos = new receptor_tres_pinos();
echo "TIPO DE TOMADA: " . $tomada_dois_pinos->getSaida() . "<br>";
echo "TIPO DE RECEPTOR: " . $receptor_tres_pinos->getSaida() . "<br>";
echo "TENTATIVA DE CONECTAR: " . $receptor_tres_pinos->conectar($tomada_dois_pinos->getSaida()) . "<br>";
echo "**FIM**". "<br>";
echo "<br>";
echo "**USAR ADAPTADOR DE 2 PINOS PARA CONECTAR RECEPTOR 3 PINOS**". "<br>";
$tomada_dois_pinos = new dois_pinos();
$receptor_tres_pinos = new receptor_tres_pinos();
$adapter_2_pinos = new dois_pinos_adapter($tomada_dois_pinos);
echo "TIPO DE TOMADA SEM ADAPTADOR: " . $tomada_dois_pinos->getSaida() . "<br>";
echo "TIPO DE TOMADA APÓS ADAPTADOR: " . $adapter_2_pinos->getSaida() . "<br>";
echo "TIPO DE RECEPTOR: " . $receptor_tres_pinos->getSaida() . "<br>";
echo "TENTATIVA DE CONECTAR: " . $receptor_tres_pinos->conectar($adapter_2_pinos->getSaida()). "<br>";
echo "**FIM**". "<br>";
?>
</body>
</html>