Skip to content

Instantly share code, notes, and snippets.

@alanwillms
Last active October 2, 2015 19:03
Show Gist options
  • Select an option

  • Save alanwillms/fa8f98acf757981dde28 to your computer and use it in GitHub Desktop.

Select an option

Save alanwillms/fa8f98acf757981dde28 to your computer and use it in GitHub Desktop.
Null Object (based on an Upcase example)
<?php
class AssinaturaGratuita extends Assinatura
{
public function isPremium()
{
return false;
}
public function getValor()
{
return 0;
}
public function cobrar(CartaoCredito $cartao)
{
}
}
// Utilização
if (null === $assinatura) {
$assinatura = new AssinaturaGratuita;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment