Created
October 2, 2015 20:20
-
-
Save alanwillms/f184cba69de36ad3afcb to your computer and use it in GitHub Desktop.
Null objects methods
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 | |
// 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