Skip to content

Instantly share code, notes, and snippets.

@DingWeizhe
Created March 6, 2019 07:40
Show Gist options
  • Save DingWeizhe/b0224b3fcd644ab095a473aceadafe8d to your computer and use it in GitHub Desktop.
Save DingWeizhe/b0224b3fcd644ab095a473aceadafe8d to your computer and use it in GitHub Desktop.
abstract class Invoice {
abstract public function validate();
}
class EmailInvoice extends Invoice {
public function validate() { }
}
class RealMailInvoice extends Invoice {
public function validate() { }
}
class InvoiceFactory {
static function createInvoice($type) {
switch ($type) {
case "RealMail":
return new RealMailInvoice();
break;
case "Email":
return new EmailInvoice();
break;
default:
return null;
}
}
}
$invoice = InvoiceFactory.createInvoice($method);
$invoice.validate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment