Created
March 6, 2019 07:40
-
-
Save DingWeizhe/b0224b3fcd644ab095a473aceadafe8d to your computer and use it in GitHub Desktop.
This file contains 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
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