Skip to content

Instantly share code, notes, and snippets.

@alanwillms
Created October 2, 2015 20:20
Show Gist options
  • Save alanwillms/f184cba69de36ad3afcb to your computer and use it in GitHub Desktop.
Save alanwillms/f184cba69de36ad3afcb to your computer and use it in GitHub Desktop.
Null objects methods
<?php
// Endereço
class Endereco
{
public function getDescricao()
{
return implode(', ', [
$this->logradouro,
$this->numero,
$this->bairro,
$this->cidade,
$this->uf,
]);
}
}
class EnderecoDesconhecido extends Endereco
{
public function getDescricao()
{
return 'Endereço desconhecido.';
}
}
// Autor
class Autor
{
public function getNomeCompleto()
{
return $this->nome . ' ' . $this->sobrenome;
}
}
class AutorAnonimo extends Autor
{
public function getNomeCompleto()
{
return 'Anônimo';
}
}
// Permissão
class Permissao
{
public function verificar($acao)
{
return !empty($this->permissoes[$acao]);
}
}
class PermissaoPendente extends Permissao
{
public function verificar($acao)
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment